ok '&' is the one which give u the address, think of something like this
Code:
int i;
when u say _________
&i --> it gives you the address of 'i' i.e where the 'i' is located in the memory | |
---------------
1000 i
so when u say &i --> it gives you the address of 'i ' in this case it is 1000
scanf the syantx is as follow
Code:
scanf("const char format", ... varibale);
scanf function always requires address of the variable in order to place the value entered by the user. u are expected to specilfy '&' in front of the variable. in your case
the scanf is expecting the address of the variable ch to place u'r char eneted in the memory
>Upon running the program, I enter in the sentence seperated by a spacebar, it would only show the first word! How do I make it so it takes the whole sentence?
that is b'cose the scanf() fucntion reads the string up to the white space the rest is lost.
the better way of doing this is to use fgets function to read the string. and this syntax is as follow
[code]
fgets(char *, int, FILE *);
[code]
example:
Code:
#include<stdio.h>
int main()
{
char str[20];
fgets(str, sizeof str, stdin); // read the string
printf("%s",str); // print the string on to the screen
getchar();
}
/* output: -
hello world
hello world
*/
hope this helps
s.s.harish