Hi. Fairly new to C. I was wondering if anyone can explain to me why this didn't work .
#include <stdio.h>
#define BUFF 256
int main(void){
char name[BUFF];
int i;
puts("Enter your FULL name and press <ENTER>");
gets(name);
for(i=0; name[i]!= '\0'; i++){
if(name[i] == ' '){
i = i-1;
}
}
printf("Your FULL NAME is: %s\nThere are %d characters in your
full name\n", name, i);
return 0;
}
I understand that I SHOULD NOT use gets as even the compiler GCC gave me a warning about using it but It was a simple program for demonstration purpose and I don't understand why it didn't work. It was supposed to display FULL name and count characters in 'name' excluding white space but I just get a new cursor after pressing <ENTER> and a blank line
thanks.