ok, this should be a quick question....
writing a Sender/Reciever program
Both files send string "ACK" to eachother, both defined in each file the same:
char ack[3]="ACK"; //defined ACK
sooo now....
before I send or recieve anything, I print out what the variable is
both have this line
printf("expected ack: %s \n",ack);
now lets see what the two files actually print.
Sender prints
expected ack: ACÿÃ1
Reciever prints
expected ack: ACKÿ
So when I send this to the other file, it doesn't compare properly.
Ideas?
(summary.... the same string declared the same way in two different files prints differently. Why?)
Posts
I know in PHP now there's an add-on to the timestamp string if you're not careful.
so, shouldn't it be?
now onto the segmentation faults!
When you quote a string, it includes the null terminator. Now your string is:
ack[0]='A'
ack[1]='C'
ack[2]='K'
ack[3]='\0' (the one you put in)
ack[4]='\0' (the one that the string automatically puts in)
ack[4] is not ack's allocated memory, so you're shoving a 0 somewhere that a 0 might not want to be.
Also, you're pointing ack to "ACK" in your data/strings section, rather than copying the letters A, C, K and \0 into ack.
The correct version is:
or