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
Post a Comment