sscanf Beginner in C


What you might be experiencing is that the variables aren’t being initialized and thus see some random values when the sscanf() doesn’t get to find the content for those missing ones. Try initializing them as following.

int int1 = 0, int2 = 0, int3 = 0;

Also, the sscanf() needs the variables addresses (hence you use &var) in order to be able to update the contents referred by them in the memory. So don’t de-reference them while printing the values held by them or when comparing them to zero (not NULL, which is meant to compare with pointers). Since the variables int1-3 are initialized you will see 0 being printed when the sscan() couldn’t read into them.

Browse More Popular Posts

Leave a Comment