C sscanf()

The sscanf() function is same as scanf() function except that the data is read from the array pointed to by buf rather that stdin.

sscanf() Syntax

int sscanf(const char *buf, const char *format, ...);

The return value is equal to the number of variables that were actually assigned values. And this number does not include fields that were skipped through use of the * format command modifiers. A value of zero means that no fields were assigned, and EOF indicates that an error occurred prior to the first assignment.

sscanf() Example

Following c program prints the message hello 1 on the screen:

void main()
	char str[80];
	int i;
	sscanf("hello 1 2 3 4 5", "%s%d", str, &i);
	printf("%s %d", str, i);

C Online Test

« Previous Function Next Function »