1.字符数组赋初值:
char arry[100] = "string init";
2.将数组值全部初始化为字符‘0’
char zero[8]; memset(zero, 0x30, 8);//‘0’的asc码值为0x30
3.字符串复制函数
strcpy(array, "test.txt");
4.字符串分割函数
strtok(“test.c”, ".");//以“.”为分隔符,分割字符串
该函数返回被分解的第一个子字符串,如果没有可检索的字符串,则返回一个空指针。
5.字符串拼接函数
strcat("test", ".txt");
二、文件相关
- fopen
fp1 = fopen("1.txt","w+");//read only
if(fp1 == NULL)
{
printf("open error!n");
return 0;
}
- fgets获取一行数据
获取文件长度
char arry[100];
int line = 0;
while (fgets(arry, 100, fp2)) // fgets循环读取,直到文件最后,才会返回NULL
line++;
3.fseek()
fseek(fp1, 0, SEEK_SET);//定位到文件开头 fseek(fp4, -1, SEEK_CUR);//定位到前一行 fseek(fp4, -1, SEEK_CUR);//定位到末尾前一行
4.fgetc
通过fgetc拷贝文件数据
char c;
while ((c = fgetc(fp1)) != EOF)
{
fputc(c, fp2);
};
- fwrite
fwrite(&b[10], 1, 4, fp1);
6.fread
FILE *fp;
char c[] = "This is runoob";
char buffer[20];
fp = fopen("file.txt", "w+");
fwrite(c, strlen(c) + 1, 1, fp);//strlen:计算字符串实际长度
fseek(fp, 0, SEEK_SET);
fread(buffer, strlen(c)+1, 1, fp);
printf("%sn", buffer);
fclose(fp);
7.fclose
fclose(fp1);



