我如何使用不同的参数回忆主要内容?

时间:2017-04-29 22:11:28

标签: c

我有我的程序,它运行就像我预期的那样,但是,我想再次调用它,但这次我想使用不同的参数。我怎么能这样做?

似乎我不能只使用main(filename1,filename2),然后遵循我之前做过的相同程序。 我的主要看起来像这样

int main(int argc,char* argv[])
{
    if (argc<3)
    {
        printf("Error no filenames\n");
        return -1;
    }
    char* filename=argv[1];
    char* fileout=argv[2];
    int count_Pharmacy;
    int count_Surgicaly;
    int count_General;
    int count_Counselling;
    char pick;

    patient* Pharmacy_head=NULL;
    patient* General_head=NULL;
    patient* Surgical_head=NULL;
    patient* Counselling_head=NULL;
    dep* dep_head=NULL;

    Counselling_head=get_patient(Pharmacy_head,filename,"Counselling");
    Surgical_head=get_patient(Pharmacy_head,filename,"Surgical");
    General_head=get_patient(Pharmacy_head,filename,"General");
    Pharmacy_head=get_patient(Pharmacy_head,filename,"Pharmacy");

    count_Pharmacy=count_patient(Pharmacy_head);
    count_Surgicaly=count_patient(Surgical_head);
    count_General=count_patient(General_head);
    count_Counselling=count_patient(Counselling_head);

    dep_head=make_deparments(dep_head,"Counselling","Dr. Willy",Counselling_head,count_Counselling);
    dep_head=make_deparments(dep_head,"Surgical","Dr. Neo Cortex",Surgical_head,count_Surgicaly);
    dep_head=make_deparments(dep_head,"General","Dr. Ann Imezechara",General_head,count_General);
    dep_head=make_deparments(dep_head,"Pharmacy","Dr. Charles Xavier",Pharmacy_head,count_Pharmacy);
    treatment(dep_head,fileout);
    printf("The patients have been treated would you like to add another file?(Y/N)\n");
    pick=fgetc(stdin);
    if (pick=='y' || pick =='Y')
    {
//this is where i would like to call main again but with diffrent arguments
    }
    else if(pick =='N' || pick=='n')
    {
        printf("Goodbye have a marvelous day\n");
    }
    else
    {
        printf("Thats not a valid input but ill take that as a no\n");
    }


    return 1;
}

我第一次称为main的两个参数是文件名。

1 个答案:

答案 0 :(得分:1)

char * new_argv [4];
int new_argc = 3;

new_argv [0] = argv [0];  // program name
new_argv [1] = "file1";
new_argv [2] = "file2";
new_argv [3] = 0;

main (new_argc, new_argv);