文件读取
#include "stdafx.h"#include <stdio.h>
#include <stdlib.h>
#include "fstream.h"
#include "string.h"
int main(int argc, char* argv[])
{
FILE *fp;
char str[5][100];
char strr[100];
FILE *frFile;
frFile=fopen("test.txt","r");
int LineNum=0;
if(frFile==NULL)
{
printf("can't open test.txt to read!\n");
exit(0);
}
int i;
for(i=0;i<5;i++)
{
fgets(strr,100,frFile);
strncpy((char*)str[i],strr,100);
}
fclose(frFile);
for (i=0;i<5;i++)
{
printf("%s\n",str[i]);
}
system("pause");
return 0;
}
我是想将test.txt文件中的数据按行读入字符串数组str[5][100]中,然后屏幕上显示出来,可出来的总是can't open test.txt to read!
请问这怎么回事,如何改正?
test文件数据如下:
sdhj125620ghij
edgh230155lk
teyu156231kl
fhgf658512650
56324565895666645120