>Will it not send theerior as the next word to my binary tree?
No, it won't. Remember that scanf is smart enough to tag a '\0' on the end of any new input. So after reading the 'e' in "the", the next element of the array gets assigned '\0', thus terminating the string. Only "the" will be sent to the tree:
Code:
#include <stdio.h>
int main ( void )
{
char *s = "the";
char buf[20] = "Superior";
printf ( "%s\n", buf );
sscanf ( s, "%19s", buf ); /* simulate the stream with sscanf */
printf ( "%s\n", buf );
return 0;
}
The issue as you see it would only occur if you tried to manually read characters and forgot to close the string:
Code:
#include <stdio.h>
#include <ctype.h>
int main ( void )
{
char buf[20] = "Superior";
int i, ch;
printf ( "%s\n", buf );
for ( i = 0; i < 20; i++ ) {
ch = getchar();
if ( isspace ( ch ) )
break;
buf[i] = (char)ch;
}
printf ( "%s\n", buf );
return 0;
}