Hi I am having problems with sscanf. I am just trying to write a simple test program to help me understand how it works. The problem arises when writing to differents variables with sscanf. Here is what their values should be:
IP=175.85.10.147
number=2589
email = [email protected]
#include <stdio.h> #include <stdlib.h> int main() { char *toSend = "175.85.10.147:2589:[email protected]"; int *number; char IP[200]; char email[300]; sscanf(toSend, "%[^:]: %i%[^:]: ", IP, number, email); printf("%s", IP); printf("%i", number); printf("%s", email); return 0; } The IP it prints correct.
The number doesn't print correctly, which might be related to this warning I'm getting at compile time: format '%i' expects argument of type 'int' but argument 2 has type 'int *'.
The email variable just contains bizarre characters for some reason.
*from the variable declaration so that it readsint number;and see if that works.%iexpects anintand you're giving itnumberwhich isint*.int *number;-->int number;,sscanf(toSend,"%199[^:]: %i:%299s", IP, &number, email);0100means sixty-four, right? if you disagree use%dinstead if%i%iwill magically parse0prefixed numbers as octal.