Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie: parsing lines

Status
Not open for further replies.

cadbilbao

Programmer
Apr 9, 2001
233
ES
Hello.

I'm trying to detect a line with this text: "OPINION"

I'm working with:
char c,c2;
while(c!=EOF)
{
c=fgetc(myfile);
if (strcmp (c,"O") ==0)
{
.......

But I consider that there's another easier option, isn't?

I would be extremely obliged of anybody could help me...
 
Read the file into a buffer. If it is case sensitive convert the buffer to uppercase and use

char* endPtr;
if(strstr(buffer,endPtr,"OPINION"))
cout<<&quot;found it&quot;;

you can also use CFiles to do this

Keep in mind that if you are not reading in the whole file, the buffer should be at least twice the length of the compare string. The reason for this is so you can shift the data left and read in the rest of the file.

for example

current buffer

abcdefghijklOPIN

shift 1/2 the buffer left

ijklOPINIONmnopqr...

Good luck

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top