我从一个文件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