petitchamp
petitchamp

Reputation: 55

What is substitute character and how to process it in windows

I get a text file from aix and try to process it on windows

but some lines contains strange character like sub character, in ultraedit , it is displayed like arrow

when fgets function encounter the line, it raise a ferror and stop at drawing. Then it refuse to continue even if I force to run fgets again on after meets the line.

The hexa code of the character is 1A

The explanation of this character in ASCII table is substitute character, which is used to replace the character that cannot be represented on the device.

Does that means

  1. I have a specific character of AIX and there is no way to process it on windows.
  2. Does this happens only in case of a cross plateform file ?

Thanks!

Upvotes: 1

Views: 2987

Answers (1)

Jabberwocky
Jabberwocky

Reputation: 50883

There are several issues.

If you use fopen with the "r" mode, the file will be opened in text mode and then the ASCII character 0x1b will be interpreted as end of file character. Furthermore if your file comes from aix, the line endings are certainly "\n" (0x10) instead of "\r\n" (0x13 0x10) on Windows, and fgets regognizes only "\r\n" as line endings.

You need to implement your own fgets like function by reading the file character by character with the fgetc function, and you must fopen the aix file with "rb" mode instead of the "r" mode.

Your new fgets like function should be no more than 5 or 6 lines long.

Upvotes: 3

Related Questions