Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > parsing error

Reply
Thread Tools

parsing error

 
 
Medvedev
Guest
Posts: n/a
 
      07-01-2008
when i try to read the first byte from an EXE file it's give different
results
code:
FILE *me,*u;
char buf_me[1];
char buf_u[1];

me= fopen(argv[0],"rb");
u= fopen(argv[1],"rb+");

fread(buf_me,sizeof(char),1,me);
fread(buf_u,sizeof(char),1,u);

printf("%s\n",buf_me);
printf("%s\n",buf_u);

----
when you run this code and put EXE file as an argument , the program
will print
M
MM

why it double the byte in the second time
 
Reply With Quote
 
 
 
 
Sleipnir
Guest
Posts: n/a
 
      07-01-2008
Put this instead:

printf("%c\n",buf_me); // %c
printf("%c\n",buf_u); // %c


You can assume your variables are one to the other into the memory. When you
send a string to printf, it's gonna write it untill it finds the character
'\0' which is not present here.



"Medvedev" <> a écrit dans le message de
news:00f88dc4-a3dd-4f4d-915a-...
> when i try to read the first byte from an EXE file it's give different
> results
> code:
> FILE *me,*u;
> char buf_me[1];
> char buf_u[1];
>
> me= fopen(argv[0],"rb");
> u= fopen(argv[1],"rb+");
>
> fread(buf_me,sizeof(char),1,me);
> fread(buf_u,sizeof(char),1,u);
>
> printf("%s\n",buf_me);
> printf("%s\n",buf_u);
>
> ----
> when you run this code and put EXE file as an argument , the program
> will print
> M
> MM
>
> why it double the byte in the second time


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What libraries should I use for MIME parsing, XML parsing, and MySQL ? John Levine Ruby 0 02-02-2012 11:15 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 09:01 PM
[ANN] Parsing Tutorial and YARD 1.0: A C++ Parsing Framework Christopher Diggins C++ 0 07-09-2007 08:58 PM
SAX Parsing - Weird results when parsing content between tags. Naren XML 0 05-11-2004 07:25 PM
Perl expression for parsing CSV (ignoring parsing commas when in double quotes) GIMME Perl 2 02-11-2004 05:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57