# include<stdio.h>
# include<string.h>

int

main(int argc, char **argv){

char phone[16];
int num = 0;
int count = 0;

	printf("Enter a phone number: ");

count = scanf ( "%s%n", phone, num );



	memmove(phone + 3, phone + 2, 10);
	memset(phone + 3, '-', 1);
	memmove(phone + 7, phone + 6, 10);
	memset(phone + 7, '-', 1);



if (count == 1 && num == 10)

	printf("Number Is %s \n num is %d\n count is %d\n" ,phone, num, count);

else
    printf("Number Is Invalid\n");

return 0;
}

This is meant to take a user inputed phone number eg 5551239876

and return a hyphenated version eg 555-123-9876

and also make sure that it is a valid 10 digit phone number

when i try to run this i get an error

:19:1: warning: format ‘%n’ expects type ‘int *’, but argument 3 has type ‘int’


i don't really understand since i have allocated num as int and i expect num to be an int, can anybody shed some light?

Thanks

scanf() expects the prameters to be pointers so that it can change the variables values. num is just an integer, not a pointer, so put the & pointer operator in front of it. count = scanf ( "%s%n", phone, &num ); Also see this article about %n.

Of course. I knew this. Thankyou very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.