I’m struggling with this for several days now.
I want to create a functions that goes through a directory, pick all the files with an extension *.csv and read the data in them.
I created a function that is supposed to check each file name that is legal, by checking that the string ends with .csv. To do this, I want to go to the end of the char * array. I tried this:
char * point = file_name;
while (point != "\0"){
point += 1;
}
which goes through the char * array without finding and “\0”.
If I write
*point != "\0"
The compiler warns me that I’m comparing and int to a char.
I should note that I get the filename using
dirent->d_name
point != "\0"compares a pointer to another pointer, which is not what you want.You want to compare whatever
pointpoints to , to a char with the value 0. So use e.g.Note, if you want to find the end of the string, you could also do
If you want to check whether a string ends in .csv, you could also do something like
EDIT : fixed formatting