Testing embedded spaces in c
I want to create a function in C programming, which will test for the embedded spaces in C.
if it found embedded spaces in a string it will return 1 else 0
'sjdfnsdj' >>>>> return 0 'sdsd sdsdf' >>>>> return 1 ' ssadsa' >>> return 0 'dfjksdnf sdfsdfdf' >>>> return 1 ' sadf asdad' >>>> return 1
Embedded spaces means spaces between two strings or after the string but NOT before a string
You could use strchr to scan the string for a space character after you you skipped leading spaces.
Assuming char buf holds the string to test
int i=0; while ( buf[i] == ' ' && buf[i] != '\0' ) i++; return strchr( &buf[i], ' ' ) != NULL;
EDIT: The post has been retagged with homework.
Instead of using strchr you can also do another loop like the one to skip the leading spaces. To find out whether there are further spaces after the first non space char.