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' )

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.

Need Your Help

DGV CellPainting behaving unexpectedly

c# winforms datagridview

I am displaying a list of hours in a DataGridView and would like to shade those hours which fall outside of business hours. I am trying to do this using CellPainting, however I am getting weird res...

Send value of text box to jquery function

javascript jquery

I have a textbox and need to send the value of the text box when you type some number and the radio button is checked, to a jquery function. The code I'm using now is: