1、使用结构体类型(自定义类型)
#define MAXSIZE 20
typedef struct{
char ch[MAXSIZE];
int len;
}String;
2、初始化字符串的方法:
String t;
StrAssign(t,"I am happy");
3、初始化一个字符串的方法如下,在最后添加'\0'
char str[] = {'I','a','m','h','a','p','p','y','\0'};
扩展资料
C语言中字符串的定义方式
第1种:
char a[5]="hello";
第2种:
char a[]="hello";
第3种:
char* a="hello";
第4种:
char a[10];
gets(a);
第5种:
char* a[5]={"hello",
"nihao",
"good",
"ok",
"bye"};