【发布时间】:2013-12-24 19:32:26
【问题描述】:
我想将 .txt 文件的内容保存到数组中。这里的事情是我首先使用该位置到另一个数组中,并且我想使用该数组保存我的位置来将文件的内容存储到一个数组中。 该代码似乎不起作用。帮助表示赞赏。
#include <stdio.h>
#include <string.h>
int main()
{
char location[50],input[1000]={0};
int i=0;
printf("Enter your file location:\n");
scanf("%999[^\n]",location);
FILE *ptr;
ptr = fopen("location", "r");
while(!EOF)
{
char c;
c = (char) fgetc(ptr);
input[i] = c;
printf("%c", input[i]);
i++;
}
input[i] = NULL;
printf("%s",input);
getch();
return 0;
}
【问题讨论】:
-
fopen("location","r");- 确定要"location"而不是location?