人生亦编程

--Programmable Life
posts - 86, comments - 43, trackbacks - 0, articles - 7

字符串数组以及结构体

Posted on 2008-01-29 20:45 人生亦编程 阅读(611) 评论(0)  编辑 收藏 引用 所属分类: 程序
 1char* test[] = {"1""12""123"};
 2 int a,b,c, d, e;
 3 a = sizeof(test);
 4 b = sizeof(test[0]);
 5 c = sizeof(test[1]);
 6 d = sizeof(test[2]);
 7 e = a/b;
 8 char f = test[0][0];
 9 char g = test[0][1];
10 char h = test[0][2];
11 char i = test[0][3];
12 printf("a%d,b%d,c%d,d%d,e%d, f%d, g%d, h%d, i%d", a, b, c, d, e, f, g, h, i);
13 
14 typedef struct
15 {
16  char a[5];
17  char b[6];
18 }
teststruct;
19 
20 teststruct t1={"1""a"};
21 teststruct testst[]= {{"1""a"},{"12""ab"},{"123""abc"},{"1234""abcd"}};
22 teststruct t2;
23 printf("%s, %s, %s, %s", t2.a, t2.b, t1.a, t1.b);
24 printf("%d, %d, %d, %d, %d, %d", testst[1].a[0], testst[1].b[0], testst[1].a[1], testst[1].b[1], testst[1].a[4], testst[1].b[4]);
25

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理