writting a C++ code to search a string from wihtin the file

Searching a string from file and using it to name the file

Page 1 of 1

1 Replies - 1831 Views - Last Post: 10 June 2008 - 01:01 PM Rate Topic: -----

#1 VS-fisher  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-June 08

writting a C++ code to search a string from wihtin the file

Posted 10 June 2008 - 11:53 AM

Hi,

I would like to know how can I checked the text of a file to retrieve only 3 characters/string from the first line and compare the string to find out if all the lines has the same string at the same position and I need to use this string to rename the file. i.e. ABC_20080610114500.oh

Attached file is 'Renaming_a_file.txt'

I need the program to read just the 3 characters starting from 2position to 5th. i.e. PABCDEF only ABC has to be derived; and the derived string 'ABC' should exist through out the file at the same position before using it to file name else it can't be renamed and should produce a log entry.

I hope this explains it clearly.

Thanks,
VS-fisher

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: writting a C++ code to search a string from wihtin the file

#2 jeronimo0d0a  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 146
  • Joined: 03-March 08

Re: writting a C++ code to search a string from wihtin the file

Posted 10 June 2008 - 01:01 PM

View PostVS-fisher, on 10 Jun, 2008 - 11:53 AM, said:

'ABC' should exist through out the file at the same position before using it to file name else it can't be renamed and should produce a log entry.


char abc[4];
abc[3] = 0; // starts @ 0 so 3 is the 4th element
for( x=0; x<3; x++)
{ abc[x] = somestring[x+1]; } // substitute the +1 if you want somewhere else in the string



Will get the three letters you want. I didn't quite understand the other part?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1