>>Let's say that I want scanf to process the following text
You'll have fewer headaches if you don't consider using scanf, ever. Reading the whole line with fgets and then breaking it up with sscanf is much nicer. :-)
Code:
#include <stdio.h>
int main(void)
{
int num;
char string[100];
/* Assume :string:ws:char:ws:number: */
if (fgets(string, 100, stdin) == 0)
{
return 1;
}
else if (sscanf(string, "%*s %*c %d", &num) == 1)
{
printf("Num -- %d\n", num);
}
return 0;
}
But if you really have to do it the ugly way, it's not much different.
Code:
#include <stdio.h>
int main(void)
{
int num;
/* Assume :string:ws:char:ws:number: */
if (scanf("%*s %*c %d", &num) == 1)
{
printf("Num -- %d\n", num);
}
return 0;
}