I wish to have a file name as an argument to the C program. I tried all the possible ways in fopen something like the below.
fp = fopen(*argv[2], "r");
Also used "*argv[2]" but did not work. I want to know where I am going wrong so that I can use this correctly. Thanks!
It should be
Please be aware that
argv[0]will contain your exe name(with path), other arguments which you pass will start fromargv[1].Refer to this for more details on using command line arguments in C.
In your main function if you are getting
char **argvas the argument, the array subscriptingargv[1]automatically turns it into achar *which is expected as an argument by fopen.