c语言纲要
发布时间: 2023-03-08 06:48:25
‘壹’ c语言如何按行读取txt中的中文字符
//若使用一维数组使用以下程序
#include <stdio.h>
main()
{
char s1[20] = {0};
char s2[20] = {0};
char s3[20] = {0};
int i=0;
FILE *fp;
fp = fopen("1.txt","r");
fscanf(fp,"%s",s1);
fscanf(fp,"%s",s2);
fscanf(fp,"%s",s3);
printf("%s\n%s\n%s\n",s1,s2,s3);
}
//若用二维数组使用如下程序
#include <stdio.h>
main()
{
char s[10][20] = {0};
int i=0;
FILE *fp;
fp = fopen("1.txt","r");
for(i=0;i<3;i++)
{
fscanf(fp,"%s",s[i]);
printf("%s\n",s[i]);
}
}
热点内容