problems passing pointers
OK, I'm quite confused as to why my passing by pointers isnt working properly...
Code:
int main() {
int type;
char input[MAX_MSG];
char username[MAX_ULEN];
char message[MAX_MLEN];
..some code..
type=0;
TeardownPacket(&input, &type, &username, &message);
printf("Type after TP: %i\n", type);
..some code...
return 0;
}
/*teardown packet def (contained in a different .c file, included above)*/
void TeardownPacket(char *input, int *type, char *username, char *message) {
/*take first byte of input data and put it in type*/
*(type) = (int) *(input);
printf("type: %i\n", *type);
..some more code..
return;
}
So I pass all those variables pointers to the function TeardownPacket. I change them successfully in TeardownPacket (I've printf'd them all and the values are correct corresponding to the data in the input string). But when TeardownPacket returns to the main function, the type variables's value that was applied in the TeardownPacket routine doesnt stay! The variable was changed in TP, but its like it went back to its original value after TP returned. I just dont get it....