C语言:简单的字符截取与比较
#include <stdio.h> struct data {char name[7];int age;} ab[5]={"张三",10,"李四",11,"张五",12,"李六",13,"陈七",14}; //编程将数组中所有姓张的年龄增加1,姓李的增加2,然后输出各个人的姓名与年龄 //中文字符串的 main() { char z[3]="张",l[3]="李"; int i; for(i=0;i<5;i++) { if(ab[i].name[0]==z[0]&&ab[i].name[1]==z[1]) ab[i].age++; else if(ab[i].name[0]==l[0]&&ab[i].name[1]==l[1]) ab[i].age+=2; printf("%s,%d\n",ab[i].name,ab[i].age); } getchar(); }