Replace wildcard text in file with specific text.

This is a discussion on Replace wildcard text in file with specific text. within the C++ Programming forums, part of the General Programming Boards category; I have a file I need to open and find "0x.xx", where x.xx is a wildcard that is all numbers. ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    Replace wildcard text in file with specific text.

    I have a file I need to open and find "0x.xx", where x.xx is a wildcard that is all numbers.
    I need to replace "0x.xx" with "01.00". The "0x.xx" is more than "01.00". Could someone give me some code to do that and then output the entire file into a new file?

    Cannot use string.

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    I'm currently using the following code to store the information I'm looking looking for in a variable, but I need to change it and reinsert it into the file. It's untested atm, but should work.

    Code:
    FILE *fp = fopen ("/somepath/file.DAT", "r" );  
    	if ( fp != NULL )
    	{	
    		char line [ 16 ];
    		if (fgets ( line, sizeof line, fp ) != NULL) {
    		sprintf(Versioninfo, "%s", strstr(line, "0")+1+strstr(line, ".")+2+strstr(line, "00")); // 0x.xx00 (IE: 01.1300)
    		return 0;
    	} else {
    		return -2;
        }
      } else {
        return -1;
      }
    Last edited by untz; 11-21-2010 at 10:28 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    Is this part of some automatic version numbering when building your software?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    Quote Originally Posted by Salem View Post
    Is this part of some automatic version numbering when building your software?
    no .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with finding word frequency in a text file.
    By aeolusaether in forum C Programming
    Replies: 15
    Last Post: 04-04-2010, 10:59 PM
  2. Help with searching text file
    By zacharyrs in forum C Programming
    Replies: 30
    Last Post: 12-01-2009, 03:13 PM
  3. Reading a specific line from a text file
    By acidrain in forum C Programming
    Replies: 3
    Last Post: 12-01-2009, 02:23 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Read SPECIFIC line from text file
    By 13373ar5 in forum C++ Programming
    Replies: 5
    Last Post: 05-21-2004, 06:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21