我從一個文件reaing,當我讀,它通過線需要它線,並打印出來從文件字符數組閱讀
是我想要的字符持有所有字符數組正是我想要的在該文件,並打印一次,
這是代碼我有
if(strcmp(str[0],"@")==0)
{
FILE *filecomand;
//char fname[40];
char line[100];
int lcount;
///* Read in the filename */
//printf("Enter the name of a ascii file: ");
//fgets(History.txt, sizeof(fname), stdin);
/* Open the file. If NULL is returned there was an error */
if((filecomand = fopen(str[1], "r")) == NULL)
{
printf("Error Opening File.\n");
//exit(1);
}
lcount=0;
int i=0;
while(fgets(line, sizeof(line), filecomand) != NULL) {
/* Get each line from the infile */
//lcount++;
/* print the line number and data */
//printf("%s", line);
}
fclose(filecomand); /* Close the file */
複製的[讀取文本文件到C中的陣列(http://stackoverflow.com/questions/410943 /讀一個文本文件到一個數組在c) – 2010-06-04 16:20:12
實際上我想要的是整個文本文件內容被保存在一個字符數組中,而不是打印,,我想使用數組的字符後來 – 2010-06-04 16:21:43
Nadeem,請參閱接受的答案tha他有聯繫。這是你想要的。基本上,字節char *是你正在談論的數組,你可以隨心所欲地做任何事情,直到你釋放它爲止。 – 2010-06-04 16:47:35