C++如何读取txt中的字母并一个一个存到数组中(该txt文件只有字母和空格)

如题,要整段代码,如果字数限制就发到我的邮箱:dalugun54321@163.com或给我留言,谢谢!

#define FILENAME

int main(void)
{
FILE * fp;
long len,i;
char *buf;

fp=fopen(FILENAME,"rt+");
if(fp==NULL)
{
printf("The file is not exeict!\n");
return -1;
}
fseek(fp,0L,SEEK_END);

len=ftell(fp);
buf=(char*)malloc(len);
if(*buf==NULL)
{
printf("Ram is out!\n");
return -1;
}
fseek(fp,0L,SEEK_SET);
fread(buf,len,1L,fp);
fclose(fp);
return len;
}
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜