Testing embedded spaces in c -


i want create function in c programming, test embedded spaces in c.

if found embedded spaces in string return 1 else 0

examples:

'sjdfnsdj' >>>>> return 0 'sdsd sdsdf' >>>>> return 1 '    ssadsa' >>> return 0 'dfjksdnf sdfsdfdf' >>>> return 1 ' sadf asdad' >>>> return 1 

embedded spaces means spaces between 2 strings or after string not before string

you use strchr scan string space character after you skipped leading spaces.

assuming char buf[] holds string test

int i=0; while ( buf[i] == ' ' && buf[i] != '\0' )   i++;  return strchr( &buf[i], ' ' ) != null; 

edit: post has been retagged homework.

instead of using strchr can loop 1 skip leading spaces. find out whether there further spaces after first non space char.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -