Sscanf gives an error, take this code:
char * args = malloc(100); strcpy(args, "Simple_str 123"); char * str; int num = 0; sscanf(args, "%s %d", str, &num); printf("%s %d", str, num); Conclusion: Simple_str 123
It seems to be the way it should be, ok, let's take this code:
char * args = malloc(100); strcpy(args, "Simple_str 123"); char * str; int num = 0; sscanf(args, "%s %d", str, &num); // <--- ошибка здесь printf("%s %d", str, num); memset(args, 0, 100); strcpy(args, "Simple_str"); sscanf(args, "%s", str); // <--- иногда здесь printf("%s; %s\n", args, str); How it works?
I compile: gcc -std=c99 main.c