C功能无法正常工作

时间:2017-11-18 17:29:40

标签: c function

对于我的代码,用户将输入一个flag参数和两个文件,输入为MIPS和要写入的输出。该标志有3个选项:-v用于程序从源代码控制(var函数)读取标签,-f用于从流控制(flo函数)读取标签,-b用于执行-v和-f命令。我的问题是-b函数不会同时执行。只是其中之一。

  void var(char *inputfile, char * outputfile) {
  FILE *input=fopen(inputfile,"r");
  FILE *output=fopen(outputfile,"w");
  /*Code Here*/
  fclose(input);
  fclose(output);

        }



void flo(char *inputfile, char * outputfile) {
  FILE *input=fopen(inputfile,"r");
  FILE *output=fopen(outputfile,"w");
  /* Code here*/

  fclose(input);
  fclose(output);

}


int main(int argc, char * argv[]) {
  char *inputfile,*outputfile;
  char flag = argv[1][1];
  inputfile=argv[2]; //Argument 2
  outputfile=argv[3]; //Argument 3

  /* check flag argument */
  switch(flag){
    /* This case produces a list of labels of the MAL source program used as
       variables in the specified output file */
  case 'v':
    var(inputfile, outputfile);
    break;

    /* This case produces a list of labels of the MAL program used for the flow control 
       in the specified output file*/
  case 'f':
    flo(inputfile, outputfile);
    break;
    /*This case produces both case v and f*/
  case 'b':
    var(inputfile, outputfile);
    flo(inputfile, outputfile);
    break;
    /*Case if user types unknown flag*/
  default :
    fprintf(stderr, "Invalid flag");
    //exit code                                                                                                                                                                                  
  }

  printf("\nCheck your output file");
  getchar();
  return 0;
 }  

0 个答案:

没有答案