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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File manipulation 1

Status
Not open for further replies.

Leibnitz

Programmer
Apr 6, 2001
393
CA
I am trying to create an application that searchs in a specific file for a string(Lets call it string1) when that string is found,it(the application)suppose to display another string(string2)which i have chosen to match string1.
I know how to search for string1 in a file but when i found it,i dont know how to display the string that match's string1(string2).
I hope that you people catch my idea,if not,tell me i'll try to reformulate.

So,any help will be very apreciated.
 
Hi,

Do you mean .. replacing string1 with string2 ? Whenever, you come across string1, you should replace it with string2 .. ??

need more explaination.
regards,
Mahesh
 
No i did'nt mean to replace String1 by String2,what i want to do is display String2 whenever String1 is enter as input.
And also,String2 has to be loaded from a file.
 
Hi,

What I understood from your post is, you want to display the string2 you found matching to string1 FROM the file. Although string1 and string2 are the same! isn't it?

I'll take it from the file prespective. You want to move back in the file to the starting point of the string you found. Moving back and forth in a file is possible through fseek() syntax:int fseek( FILE *stream, long offset, int origin );

for your case, you may use:
Code:
fseek(fp,-(sizeof(char)*strlen(string1),SEEK_CUR);
fgets(string2,strlen(string1),fp);

where fp is your file pointer. For further details, see fseek documentation.

Chow!

Roy
user.gif
 
String2 has to be another string,it has to be different from String1.But whenever a user enter String1 as input,i want to display String2 at that moment.String1 and String2 are both has to be loaded from a file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top