首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

一个很简单的有关问题 关于文件打开出错

2012-05-24 
一个很简单的问题 关于文件打开出错源码:#include stdio.h#include stdlib.h#include unistd.h#incl

一个很简单的问题 关于文件打开出错
源码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#define BUF 1024
int main(int argc,char **argv)
{
FILE *from_fd,*to_fd;

  if(argc!=3)
  {
  printf("argument error");
  exit(1);
  }
  if((from_fd=fopen(argv[1],"w+b"))==NULL)
  {
  printf("open %s failure\n",argv[1]);
  exit(1);
  }
  if((to_fd=fopen(argv[2],"w+b"))==NULL);
  {  
  printf("OPEN FILE %s ERROR\n",argv[2]);
  exit(1);
  }
}
运行时:
qust@qust-K42JZ:~/test$ gcc fopen_file.c -o fopen_file
qust@qust-K42JZ:~/test$ ./fopen_file test.c newfile
OPEN FILE newfile ERROR
test.c newfile这两个文件都是不存在的,创建这两个文件为什么会出错呢??
但实际在目录下创建了这两个文件。望大家指教,谢谢!

[解决办法]
if((to_fd=fopen(argv[2],"w+b"))==NULL);
去掉后面的分号
[解决办法]
楼上正解,因为无论如何,你都会走下面的
printf("OPEN FILE %s ERROR\n",argv[2]);
exit(1);

热点排行