I guess you wanted to ask, why is it scanf ("%s", array)and not scanf ("%s", &array).
Well, array is by definition a pointer to the first element: array = &array[0]
#include,stdio.h>main(){char string1[20],string2[20]printf("enter the first string");scanf("%s",string1);// reading the string1printf("enter the second string");scanf("%s", string2);// reading the the string2printf( "the first string is %s",string1);// printing the string1printf("the second string is %s",string2);// printing the string2}the problem of using scanf is that it does not take space. so we can use gets for it.ie instead of scanf("%s",string1); we can use gets(string1); .
printf: format string + value list scanf: format string + address list
scanf ("%[^\n]s", sentence);
Certainly. That's what sequence %s is good for.
scanf is used for reading formatted data from stdin. The general syntax is:scanf( format , arguments);For more information on scanf, visit the link below.
By using the scanf statement in c,we can take the values at run time . for ex a is a variable of type int so, we can assign the value of a using scanf at run time as follows. scanf("%d",&a); here %d is the conversion specifier for integer type.
cause getchar only read a character and scanf read only word before first space but not other words and letters.
#include<stdio.h> #include<conio.h> #include<string.h> void main() { char a[15],b[15]; printf("Enter the string\n"); scanf("%s",&a); strcpy(b,a); strrev(a); if(strcmp(a,b)==0) printf("The String is a palindrome"); else printf("The String is not a palindrome"); }
scanf();
int scanf(char* format, ...); the format accepts the format specifier string, the elipsis operator accepts the variable list scanf("var type var type ...", &var, &var, ...); example: int num1, num2, num3; scanf("%d %d %d",&num1,&num2,&num3); Is that what you were looking for? Maybe this can help also...
int main (void) { char buf[1024]; scanf ("Enter a string: %s", buf); printf ("The length of the string is %d chars long.\n", strlen (buf)); return 0; }
AnswerYou can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value); The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.AnswerIf you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:printf("%*d", width, num);That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.