首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

不能打开资料

2012-09-24 
不能打开文件#include stdio.h#include stdlib.hint main (void){char source[10], destination[10],

不能打开文件
#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;} 

热点排行