Reputation: 139
I have my program and it runs like I expected, however, I want to call it again but this time I want to use different arguments. How can I do that?
It seems I cant just use main(filename1,filename2)
and then follow the same routine I did last before.
My main looks like this
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;
}
The two arguments I called main with the first time are file names.
Upvotes: 0
Views: 86
Reputation: 15310
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);
Upvotes: 1