这是我目前拥有的代码,但似乎无法编译。如有任何帮助,我们将不胜感激。
#include <stdio.h>
main (void)
{
FILE *textfile1;
FILE *textfile2;
int c;
char Filename;
printf("Enter the name of text file:");
scanf("%s", &Filename;
textfile1 = fopen(textfile1, "r");
if (textfile1 == NULL)
{
printf("File not found");
}
else
{
while (fscanf(textfile1, "%c", &textfile1) == 1)
{
printf("%c", textfile1);
}
fclose(textfile1);
}
}
#include <stdio.h>
int main (void) /* you had better specify the return value explicitly */
{
FILE *textfile1;
FILE *textfile2;
int c;
char Filename[1024]; /* allocate enough buffer to store the name */
char textfiledata1; /* add this to store the data from file */
printf("Enter the name of text file:");
scanf("%1023s", Filename); /* add ), and other change including limit of length to read to avoid buffer overrun */
textfile1 = fopen(Filename, "r"); /* you have to pass the name. Do not pass the uninitialized file pointer! */
if (textfile1 == NULL)
{
printf("File not found");
}
else
{
while (fscanf(textfile1, "%c", &textfiledata1) == 1) /* store the data from file to the file pointer? nonsense. */
{
printf("%c", textfiledata1);
}
fclose(textfile1);
}
return 0; /* explicitly return something is a good practice */
}