954,173 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help writing a grep program

Hi Everyone
I have to write a grep program in C and I am not sure where to start. :?:
I need to use strstr() from the standard library, and get it to work; but I dont know how to do that.
And that's only half the program, the second part is "getting strstr() to do case-insensitive searches"... But the professor says it can't; "you know what happens when you know what verb you need, you know what you need it to do, but it isn't available?... you write it" I am not sure what that means and I have no clue what strstr() means! If someone could just help me get started i would really appreciate it. This is my first time taking programming and It is soooo much harder than I thought!
Thanks In Advance!

kiki021600
Newbie Poster
6 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

strstr is a standard function that searches for occurrances of one string inside another.
This is exactly what grep does at its most basic.
It can indeed not search case insensitive but with a little thinking you will be able to figure out how to use it anyway.
Hint: how do you turn "Hello" into "HELLO"?

Your professor seems like a wise man making that statement. He tells you to first think about how you'd solve the problem rather than sit down and start coding like a maniac.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

strstr is a standard function that searches for occurrances of one string inside another. This is exactly what grep does at its most basic. It can indeed not search case insensitive but with a little thinking you will be able to figure out how to use it anyway. Hint: how do you turn "Hello" into "HELLO"?

Your professor seems like a wise man making that statement. He tells you to first think about how you'd solve the problem rather than sit down and start coding like a maniac.



I dont know how to turn hello into HELLO!
I would like to sit down and code like a maniac, I understand whta to do but putting it in computer language is hard for me.

kiki021600
Newbie Poster
6 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

i think u can easily convert "hello" to "HELLO" by using toupper() function

harshchandra
Junior Poster in Training
68 posts since Nov 2004
Reputation Points: 7
Solved Threads: 1
 

char * strcasestr (const char *haystack, const char *needle)

This is like strstr, except that it ignores case in searching for the substring :lol:

frrossk
Posting Whiz in Training
220 posts since Sep 2004
Reputation Points: 17
Solved Threads: 9
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You