Hi, I'm having issues with perror(), it's printing before an fprintf call which occurs before it. The tokptr variable is correct, I'm also aware that errno should be saved if perror isn't ocurring directly after fopen(), though fprintf AFAIK does not alter the errno and it certainly isn't not-printing ;p
Output:Code:if( fopen(tokptr,"r") == NULL ) { fprintf(stdout,"%s\n", tokptr); /* Test */ fprintf(stdout,"Error opening settings file %s: ",tokptr); perror("Error opening tokptr"); exit(1); }
The code will print the perror() string before it prints the fprintf string, unless the fprintf string has a newline character at the end, like so:Code:saec@saeculum:~/GA3$ ./GASim-helper --settingsFile="loo.ini" loo.ini No such file or directory Error opening settings file loo.ini
I have similar code in a different file, where the fprintf occurs before the perror, and it prints in this order.Code:fprintf(stdout,"Error opening settings file %s\n: ",tokptr);
This is the code that works as it should - when testing, this code isn't reached so plays no part in the issue.
Can anyone shed some light onto this, my only idea was that tokptr wasn't correct, but it is.Code:if( freopen(argv[1], "a", stdout) == NULL ) { fprintf(stdout,"Error with freopen(): "); perror(""); return 0; }



LinkBack URL
About LinkBacks


