arrays - How to check spaces in a string C? -


i trying have program take name input user , print out initials of name. i.e. tommy brown --> tb

what have far this:

int main (void) {  char scroll[100] = {"kang cheng junga"}; printf ("%c\n", *(scroll+2));  (int i=0; i<100; i++) {     if (*(scroll+i)=" ")     {         printf (*(scroll+i+1));     } } 

i keep getting error:

error: incompatible pointer integer conversion assigning 'char' 'char [2]'

[-werror,-wint-conversion] if (*(scroll+i)=" ")

error: using result of assignment condition without parentheses

[-werror,-wparentheses] if (*(scroll+i)=" ")

can tell me how i've screwed up? having hard time understanding how * , & function in c. beginner don't know i'm doing.

in c, = assignment operator, , == equality operator. need use later one.

that said, there nice library function, named strtok() can make life easier. pass string , delimiter, (here, space ) , return token you, can print first character initials.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -