473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fgetc returns the wrong character (0a -> 0d)

I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be 0d.
In the Memory of f (buffer) it is 0a. What the Hell is going wrong here. I
calculated the offset und figured the chars are the same position. Memory
Error is not possible since I look at the Memory just after the Buffersize
was 0. (Means the MSL just filled the Buffer again). When I change the 0d to
0a it does exactly the opposite.

Nov 14 '05 #1
8 5072
begin followup to Georg Troxler:
I try to parse a file. When I read a int with fgetc(f) I get the
wrong result. When I open the file with a Editor I see clearly the
character should be 0d.


Unix uses \xA for a line feed.
DOS, Windows, NT and OS/2 use \xD\xA for a line feed.
MacOS <= 9 uses \xD for a line feed.

Some implementations on these platforms convert the OS specific line
feed into "\xA" on input. See your vendors documentation for the
keywords 'binary mode'. Probably specifing character 'b' to argument
mode of mode should do.

--
Für Google, Tux und GPL!
Nov 14 '05 #2
"Georg Troxler" <ge***********@yaksoft.com> wrote in message
news:BC399A40.4B47%ge***********@yaksoft.com...
I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be 0d. In the Memory of f (buffer) it is 0a. What the Hell is going wrong here. I
calculated the offset und figured the chars are the same position. Memory
Error is not possible since I look at the Memory just after the Buffersize
was 0. (Means the MSL just filled the Buffer again). When I change the 0d to 0a it does exactly the opposite.


Open the file as binary and you won't get this mapping that
seems to irritate you.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Nov 14 '05 #3
On Sun, 25 Jan 2004, Georg Troxler wrote:
I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be 0d.
In the Memory of f (buffer) it is 0a. What the Hell is going wrong here. I
calculated the offset und figured the chars are the same position. Memory
Error is not possible since I look at the Memory just after the Buffersize
was 0. (Means the MSL just filled the Buffer again). When I change the 0d to
0a it does exactly the opposite.


How was the file opened? If you open it as a text file, i.e. "r" rather
than "rb", then what is stored on the system and how it comes in the
stream can be different.

Try opening the file as binary and see if that solves your problem.

--
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vi************@whitehouse.gov
Nov 14 '05 #4
In 'comp.lang.c', Georg Troxler <ge***********@yaksoft.com> wrote:
I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be
0d. In the Memory of f (buffer) it is 0a


Open the file in binary mode ("rw") for a raw process of the data.

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #5
Emmanuel Delahaye wrote:
In 'comp.lang.c', Georg Troxler <ge***********@yaksoft.com> wrote:

I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be
0d. In the Memory of f (buffer) it is 0a

Open the file in binary mode ("rw") for a raw process of the data.


ITYM "rb". "rw" implies read/write, which I don't think is implemented
by the standard library.

--
My address is yvoregnevna gjragl-guerr gjb-gubhfnaq guerr ng lnubb qbg pbz
Note: Rot13 and convert spelled-out numbers to numerical equivalents.
Nov 14 '05 #6
In 'comp.lang.c', August Derleth <se*@sig.now> wrote:
Open the file in binary mode ("rw") for a raw process of the data.


ITYM "rb". "rw" implies read/write, which I don't think is implemented
by the standard library.


Your are correct, and I was dumb. Apologies.

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #7
In 'comp.lang.c', Emmanuel Delahaye <em**********@noos.fr> wrote:
Open the file in binary mode ("rw") for a raw process of the data.


Of course, I meant "rb".

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=cpp
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #8
In <5b******************@fe02.usenetserver.com> August Derleth <se*@sig.now> writes:
Emmanuel Delahaye wrote:
In 'comp.lang.c', Georg Troxler <ge***********@yaksoft.com> wrote:

I try to parse a file. When I read a int with fgetc(f) I get the wrong
result.
When I open the file with a Editor I see clearly the character should be
0d. In the Memory of f (buffer) it is 0a

Open the file in binary mode ("rw") for a raw process of the data.


ITYM "rb". "rw" implies read/write, which I don't think is implemented
by the standard library.


It is implemented, but it's spelled "r+" or "w+" (the former preserves
the contents of the file upon opening, the latter wipes it out).

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: William L. Bahn | last post by:
I'm sure this has been asked before, and I have looked in the FAQ, but I'm looking for an explanation for the following: The functions pairs: gets()/fgets() puts()/fputs() printf()/fprintf()...
6
by: Kobu | last post by:
Do the "larger" input functions like scanf, gets, fgets use fgetc to take input or an operating system call function like read() (I know it could be any "way", but I'm trying to find out how it's...
2
by: Mark | last post by:
i'm trying to read a file one char at a time into a char array thusly... char buffer; while (readChars(InputFile, buffer, BUFFER_SIZE) != 0) { //not doing anything atm } int readChars(FILE...
8
by: M. Åhman | last post by:
I'm reading "C: A Reference Manual" but still can't understand a very basic thing: is there any functional difference between fgetc/fputc and fread/fwrite (when reading/writing one unsigned char)?...
3
by: cinsky | last post by:
Hi, While reading ISO C Standard, I found follow text in 7.19.8.1: size_t fread(void *restrict ptr, size_t SIZE, ...) ... For each object, SIZE calls are made to the fgetc function and the...
37
by: 01 | last post by:
#include <stdio.h> int main ( int argc, char *argv ) { if ( argc != 2 ) /* argc should be 2 for correct execution */ { /* We print argv assuming it is the program name */ printf( "usage: %s...
8
by: pavan734 | last post by:
Hi I have got a file "file_data.in" that contains the following data: abcdef I have a code that reads character by character & display it. But to my surprise it is printing one character more at...
4
by: Christopher Benson-Manica | last post by:
In a thread from substantially earlier this week, Harald van D?k <truedfx@gmail.comwrote: Being rather pendantic, I decided to try to verify whether this was true. I would appreciate...
9
by: primeSo | last post by:
// FIRST int main(void){ int c, i = 0; char cArray; while( (c = getchar()) != '\n' && c != EOF){ cArray = c; i ++; }
11
by: phpnewbie26 | last post by:
I am trying to read the first character in an array but my syntax seems to be wrong as it says I have an error. I have read each line a text file into an array and by using fgetc, I'm trying to see...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.