I started to learn C and I am writing a code where the user needs to type a string he wants to search in the csv file , and if the string was found , it will print the number of line the string was found at . and I am not exactly sure what is the best way to do that
Asked
Active
Viewed 845 times
-1
-
4Please provide a minimal attempt. You probably want to use fopen to open a file, fgets to get string, count lines, and search lines. see: http://stackoverflow.com/questions/3501338/c-read-file-line-by-line and: http://stackoverflow.com/questions/9206091/going-through-a-text-file-line-by-line-in-c – ChuckCottrill May 08 '17 at 21:05
-
Please provide some code here first which shows an attempt at solving this problem. – Nguai al May 08 '17 at 21:05
-
This sounds like 'run `grep -n` on the CSV file'. If that's not appropriate, you need to think about how you'll do it. Probably open the file, read lines, keeping a count, and searching each line (and closing the file at the end). Sounds pretty routine — `fopen()`, `fgets()`, `strstr()`, `printf()`, `fclose()`. [What have you tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) — See also MCVE ([MCVE]). – Jonathan Leffler May 08 '17 at 21:16