Results 1 to 4 of 4

Thread: Replace a letter wchar_t by another in a file. (Unicode)

  1. #1
    Join Date
    Nov 2008
    Posts
    1,192

    Replace a letter wchar_t by another in a file. (Unicode)

    I'd like to know how exactly to replace one letter by another in a file containing Unicode characters (wide characters (wchar_t)). I try with the following code, but it does not work, I get every time an endless loop:

    Code:
    do
    {
       letter = fgetwc (file);
       //printf("%d\n", debug++); 
       if( letter == 'a')
       {
          //puts("OK" ); 
          fseek(file, - sizeof(wchar_t), SEEK_CUR);
          fputwc('b', file);
       }
    }
    while(letter != WEOF);

  2. #2
    Join Date
    May 2008
    Posts
    271

    Re: Replace a letter wchar_t by another in a file. (Unicode)

    if( letter == 'a')

    I doubt there. wchar_t is a letter, surprised that it might be equal to a char.

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: Replace a letter wchar_t by another in a file. (Unicode)

    Yeah actually sizeof (wchar_t) is dependent on the system. On Mac OS X, it is 4, on Windows it is 2.

    Windows uses UTF-16, which comes in two versions: Big endian and little endian. However, if the file is created and played on the same machine, you should be fine.

    In short, should be careful what you read. Put a printf to see whether it is the ascii code of 'a' that gets you a value and not distorted by the endianness.

    That's why I prefer UTF-8, this need not take the lead with such details.

  4. #4
    Join Date
    May 2008
    Posts
    945

    Re: Replace a letter wchar_t by another in a file. (Unicode)

    @ void

    We left for a technical subjects less well understood by the median programmer...

    1. wchar_t is not necessarily Unicode.

    2. As you like, as a result of narrow or wide, a file to multibyte encoding depends on the local, thus two different characters may occupy a different place in the file, the only possible solution is to copy in making the transformation you want, then delete the original file (or rename), then rename the file that you copy.

    3. Where it is planned to have local non-use of encoding variables, I do not know the local I know who use, use wchar_t for Unicode UTF-8 as encoding.

    fseek(file, - sizeof(wchar_t), SEEK_CUR);
    1. In a text file, it can not be possible so as to travel to positions previously returned.

    2. sizeof (wchar_t) is a constant of compilation, even if you have a local encoding uses a fixed size, there priory no connection between this size and sizeof (wchar_t).

Similar Threads

  1. Best utility to replace Windows File Copier
    By Uganda in forum Windows Software
    Replies: 4
    Last Post: 28-05-2012, 01:25 PM
  2. Replies: 8
    Last Post: 30-10-2011, 11:05 PM
  3. How can I replace System file of Samsung Captivate
    By PlowMan in forum Portable Devices
    Replies: 5
    Last Post: 23-05-2011, 08:22 PM
  4. Non-gui tool to modify unicode .ini file
    By cheerful in forum Windows Software
    Replies: 2
    Last Post: 25-08-2009, 09:12 PM
  5. Cannot replace a DLL file in system32
    By Andrew in forum Vista Help
    Replies: 7
    Last Post: 27-01-2009, 12:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,328,615.37411 seconds with 16 queries