So it give me an error using if(argv[i]=="-o"). Is there a different function I can use.
You can't compare strings like this in C:
if(argv[i]=="-o")
That just compares the addresses of the character arrays.
What you need is:
if(strcmp(argv[i],"-o") == 0)
This actually runs through the 2 strings and returns 0 if all characters are the same.
The first loop tries to open all the parameters as files, so if a -o occurs before a filename, it will try to open the file "-o"
You are comparing a string with ==, which won't do what you are intending, as it only compares the pointers, not the string itself. try strcmp instead
If the -o is the last parameter you will get a memory fault, as when you find a -o, you then blindly read from argv[i+1], even if i=argc-1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.