parsing error

M

Medvedev

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
 
S

Sleipnir

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top