1

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!

4
  • 1
    It's just an ASCII control code and it should not cause problems within a call to fgets. It's more likely a bug in your code, which you should add to your question. Commented Mar 19, 2014 at 9:50
  • Ths SUB character (ASCII code 1A) is an unprintable character, but it should not cause problems with fgets. Try to read your file character by character with the fgetc function and see what happens. Commented Mar 19, 2014 at 9:50
  • 2
    In Windows, 0x1A is commonly interpreted as end-of-file tag for text files. If you try to execute type file.txt command in command prompt, it will also stop at such character if the file has one. Commented Mar 19, 2014 at 9:52
  • @AndreyChernyakhovskiy It seems that your answer is the most accurate.thanks Commented Mar 19, 2014 at 10:02

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.