I would like to read from a .csv file line by line and then check if the first word of my line matches string_1. If it matches, then I would also like to check if the second word matches string_2. My .csv file contains three fields, namely user, password and type.
Here is my code so far:
void verify ( char *user, char *password ) {
FILE *data;
char verifyUser[50];
data = fopen( "password.csv", "r+" );
while ( fgets(verifyUser, 50, data ) != NULL) {
char *ptr;
ptr = strtok(verifyUser, ", ");
/***What do I do here?***/
}
fclose(data);
}
In this case, user and password are string_1 and string_2 respectively. Any tips? Can I use strtok to split my line into three substrings, and then perform strcmp on them? If so, how do I do that?
How about something along these lines:
Of course this code assumes you already trust the strings
userandpasswordand it’s also untested.