I currently have a .csv file containing three fields: user, password, type. For instance, my file looks like this:
michael, sun123, user
joseph, sierra7, user
isaac, apple2, sysop
I would like to read from such file and check if the user "isaac" is present in the list. So far, I was able to open the file and put every characters of my file into a 1D array called database[]. I have set a pointer pointing to the very first character of my database[] array. My question is: How do I manage to find "isaac" in the file?
My idea was to check if the first character of the user I am looking for matches a character in my array. If so, I begin to check the next characters as long as I don't hit a comma. When I hit a comma, I then check if there exits a password, a comma and a type before a carriage return using boolean. Is there an easier way of doing this?
Thanks in advance!
You can use the result of
strstr(database, "isaac");
to find "isaac" in yourdatabase[]
.You can use
strtok
(or it's safe variants, detailed here http://msdn.microsoft.com/en-us/library/ftsafwz3(v=vs.80).aspx) to break yourdatabase[]
up into more manageable items (ie. tokenize on commas and newlines) for your parsing needs.A combination of
strtok
andstrstr
orstrcmp
may be what you want.