Sample2


#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[ ]){
  int i;
 char ch;
 FILE *FP;

 /* if not file name and string stop program */
 if (argc <= 2){
  printf("Please input file name and string. Try again!\n");
  exit(1);
 }

 /* if file exists, stop program */
 if ((FP = fopen(argv[1], "r")) != NULL){
  printf("File Exist!\n");
  fclose(FP);
  exit(1);
 }

 /* write string to the file */
 FP = fopen(argv[1], "w");
 fprintf(FP, argv[2]);
 while(scanf("%c", &ch) != EOF){ /* if you find EOF character, exit this loop */

  }
 fclose(FP);
}



2003年5月3日 13:12 更新