不能打开文件
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
char source[10], destination[10], buff[1024];
FILE * fp1, * fp2;
puts("Enter the name of suorce filename.");
scanf ("%s", source);
puts("Enter the name of destination filename.");
scanf ("%s", destination);
if ((fp1 = fopen(source,"rb")) == NULL);
{
fprintf (stderr, "Can't open %s.", source);
exit (1);
}
if ((fp2 = fopen(source,"wb")) == NULL);
{
fprintf (stderr, "Can't open %s.", destination);
exit (1);
}
while (fscanf (fp1, "%s", buff) != EOF)
fputs (buff, fp2);
fclose (fp1);
fclose (fp2);
return 0;
}
这个程序我运行的时候显示不能打开SOURCE文件则么回事?
[解决办法]
- C/C++ code
#include <stdio.h>#include <stdlib.h>int main (void){ char source[10], destination[10], buff[1024]; FILE * fp1, * fp2; puts("Enter the name of suorce filename."); scanf ("%s", source); puts("Enter the name of destination filename."); scanf ("%s", destination); if ((fp1 = fopen(source,"rb")) == NULL); // ======= 多了; { fprintf (stderr, "Can't open %s.", source); exit (1); } if ((fp2 = fopen(source,"wb")) == NULL); // source应为destination ======= 多了; { fprintf (stderr, "Can't open %s.", destination); exit (1); } while (fscanf (fp1, "%s", buff) != EOF) fputs (buff, fp2); fclose (fp1); fclose (fp2); return 0;}