1. 程式人生 > >Windows系統中控制檯下編譯C/C++檔案

Windows系統中控制檯下編譯C/C++檔案

 #include<stdio.h>
int main(int argCount,char* argValue[])
{
    FILE *srcFile=0,*destFile=0;
    int ch=0;
    if(argCount !=3)
    {
       printf("Usage:%s src-file-name dest-file-name/n",argValue[0]);
    }
    else
    {
       if((srcFile = fopen(argValue[1],"r"))==0)
       {
          printf("Can not open source file /"%s/"!",argValue[1]);
       }
       else
       {
          if((destFile = fopen(argValue[2],"w"))==0)
          {
             printf("Can not open destination file/"%s/"!",argValue[2]);
             fclose(srcFile);
          }
          else
          {
              while((ch=fgetc(srcFile))!=EOF) fputc(ch,destFile);
              printf("Successful to copy a file!/n");
              fclose(srcFile);
              fclose(destFile);
              return 0;
          }
        }
      }
      return 1;
}