| | |
fread problem?
![]() |
Hi. Can anyone help me to distinguish the reason behind this case? Thanks a lot.
I initialized the following variable: unsigned char temp=0;
In the following statement block, I managed to get the results that I wanted to be displayed on the first go (traversing the while loop on the first run).
However, on the 2nd run, the temp being printed equals to the last temp printed in the first run.
while
{
// other print statements
// statement to get rlen
for(i=0; i<rlen; i++)
{
fread( (char*) &temp, sizeof(temp), 1 ,input);
printf("%x ", temp);
}
}
I've thought of it might be because of pointer problems? I am not sure. I am not any good at this, just a beginner. Please help. Thanks.
I initialized the following variable: unsigned char temp=0;
In the following statement block, I managed to get the results that I wanted to be displayed on the first go (traversing the while loop on the first run).
However, on the 2nd run, the temp being printed equals to the last temp printed in the first run.
while
{
// other print statements
// statement to get rlen
for(i=0; i<rlen; i++)
{
fread( (char*) &temp, sizeof(temp), 1 ,input);
printf("%x ", temp);
}
}
I've thought of it might be because of pointer problems? I am not sure. I am not any good at this, just a beginner. Please help. Thanks.
•
•
Join Date: Dec 2003
Posts: 55
Reputation:
Solved Threads: 6
C Syntax (Toggle Plain Text)
for (int i = 0; i < rlen; i++) { printf("%x\n", fgetc(input)); }
do it that way
Thanks a lot for your reply.
I've tried and hey, the output differs, however it's still not what I expected it to be.
The first loop:
The second loop:
I've tried and hey, the output differs, however it's still not what I expected it to be.
The first loop:
C Syntax (Toggle Plain Text)
a1 b3 8 9a // which is correct
The second loop:
C Syntax (Toggle Plain Text)
9a 9a 9a 9a // before r0ckbaer's advice
C Syntax (Toggle Plain Text)
ffffff // after applying to r0ckbaer's advice ffffff ffffff ffffff
•
•
Join Date: Dec 2003
Posts: 55
Reputation:
Solved Threads: 6
Well, normally fgetc gets one char per loop (in the above example) and increments the file pointer with 1, so:
a1 b3 8 9a
would be a result after 4 loops.
Be more specific on how you want the output to look like and if possible paste a snapshot of the hexdump of lets say the first 50 bytes of the file u want to analyze.
a1 b3 8 9a
would be a result after 4 loops.
Be more specific on how you want the output to look like and if possible paste a snapshot of the hexdump of lets say the first 50 bytes of the file u want to analyze.
Well, it's a project for computer networks actually.
I am to capture packets using a program called windump, and then decode each field of information in their respective ethernet frame, ip frame, tcp/udp frame.
It seems that the results is not stable, in some packets, I could get the correct output, while not in some other packets.
Is it always like that? (Now, it seems like it has to be in the 'networking' topic & not c already!)
This is because, I strongly feel that there is no problem with the codes. I've got a comment from a coursemate that output will be more accurate using bigger packet files. :!: Please advise. Thanks.
I am to capture packets using a program called windump, and then decode each field of information in their respective ethernet frame, ip frame, tcp/udp frame.
It seems that the results is not stable, in some packets, I could get the correct output, while not in some other packets.
Is it always like that? (Now, it seems like it has to be in the 'networking' topic & not c already!)
This is because, I strongly feel that there is no problem with the codes. I've got a comment from a coursemate that output will be more accurate using bigger packet files. :!: Please advise. Thanks.
•
•
Join Date: Mar 2004
Posts: 77
Reputation:
Solved Threads: 2
•
•
•
•
Originally Posted by r0ckbaer
C Syntax (Toggle Plain Text)
for (int i = 0; i < rlen; i++) { printf("%x\n", fgetc(input)); }
do it that way
![]() |
Similar Threads
- Problem with fread and malloc (C++)
- Serious problem with attchments-please help (PHP)
- read in using fread() for arbitrary length data (C)
- problem opening files (C++)
Other Threads in the C Forum
- Previous Thread: error checking help
- Next Thread: Need help with Const, Ref and Classes.
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi





