Sent this to support today and got an automated response to ask this afl related question here instead.
In words, load the contents of a file into a string variable. Each
line of content is a complete path to another file. Then open each file.
All files are located in the same directory:
The content of "C:\test\FileList.csv" is:
C:\test\1.csv
C:\test\2.csv
C:\test\3.csv
The content of each of these files 1.csv, 2.csv, and 3.csv, is:
line 1
line 2
line 3
The first call to fopen() works correctly. The call to fopen() inside
the loop doesn't work for the first and second loop, but does work on
the third loop. What am I missing?
When âfileListStrâ is built in the âwhileâ loop, the first character in the resulting string becomes a comma. The code uses a start position of â1â to trim off this leading comma.
From this:
â,C:\test\1.csv,C:\test\2.csv,C:\test\3.csvâ <-- leading comma
to this:
âC:\test\1.csv,C:\test\2.csv,C:\test\3.csvâ <-- leading comma removed
fopen() is (almost) direct call to C runtime library so it works. If it does not work, you are doing something wrong. In your case the reason is probably very simple - there are characters that you do not see (so called âwhite spacesâ) in the names.
For example, if you have file names each in separate line, fgets() will get the file name together with new line '\n' and/or '\r' (invisible, white character). If you try to pass file name with new line character appended at the end fopen() would fail because there is no such file (with new line character at the end). You would need to trim whitespaces from the end of the line (using StrTrim() function).
Debugging does not hurt. It is all about using debugger and/or TRACE() to find out what is happening in your code.
Now look how much everyone can gain from answering on forum. Now everyone can learn something new.
Thank you. The automated response I was referring to was the initial response from support containing the ticket number. The fgets documentation does indeed state âfgets reads characters from the current file position to and including the first newline character.â My bad. This makes sense in my situation because the 1st and 2nd lines have a newline character (and were a problem) but the third line does not. The debugger is great. Use it and _TRACE all the time.