Issue
Please help me. I'm new to programming. I've been trying and searching for days to answer this.
I need a C program that will open a text file named users.txt
In that text file there are names then comma and their schools.
John Paul, Legit Univ
Paul John, Yo Univ
Lebron James, School Univ
James Lebron, Legit Univ
All I managed so far is to display them all. The output should be all the users that are from "Legit Univ"
.
Sample output:
Found 2 users from Legit Univ
John Paul
James Lebron
Solution
Use fgets()
to read a line from file into a string, then strchr()
to to find the position of the comma ',' field separator in the string (or strstr()
if the field separator is comma space ", "). Now you can check the part of the string after the field separator for a match on your query with strcmp()
. Instead of parsing the file, you could also use a regex and match against the string.
Answered By - Allan Wind Answer Checked By - Katrina (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.