Here is my practice code:
int integer_part;
char* string_part = (char*)malloc(sizeof(1000));
char* input_string = (char*)malloc(sizeof(1000)+sizeof(int));
cin>>input_string;
sscanf(input_string, "%s %d", string_part, &integer_part);
printf("scan: %s %d", string_part, integer_part);
I am using this code to take input like abc 2012 but the result will be abc 0
Sadly I didn’t see where the problem is. Can anyone help me with this a little? thank you
This reads only first space delimited string:
Use this way:
Don’t mix C++ and C way of reading from streams.
You can use this way to read string without space delimited:
I can understand you need the power of
scanfto read data in a given format.