Hello, I am still trying to figure out a problem that I was given about 2 weeks
ID: 3620361 • Letter: H
Question
Hello, I am still trying to figure out a problem that I was given about 2 weeks ago (it was due last week). I have most of it figured out (with help from this site) except for one part..Say there are multiple lines, and you want to delete a line that doesn't include certain characters :
a house is blue
the dog is brown
i read a history book
etc.(there are a lot more than 3 lines, but an example for these three lines would be great)
I want to read through a line, search for the characters "a" and "h", and delete any line that does not include an "a" and "h".
For the above example, the output would be:
the dog is brown
I know how to read an input file and copy the output to another file, so it is just the code that would help with this example that I need. I have access to the string.h library, which I think may have the functions I need to complete this problem?
Thanks for your help and I will definitely rate any helpful answers
Explanation / Answer
You could use the strchr which is part of string.h. If the 'a' letter was not in the char then it would return a null pointer. So for example you could do: char buffer[] = "the dog is brown"; if(strchr(buffer,'a') != null || strchr(buffer,'h') != null) { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.