This small piece of code takes a user input and returns the last word from the user input.
I don't exactly understand how those 2 lines of code work
can someone explain why or how printf( &last_word[i]);
when I is at position 0 prints the last word of the sentence entered by the user input.
the purpouse of the program is to print the last word of the user input, but I dont understand those lines of code, If I change something on those 2 lines, the code stops working and it doesnt return the last word entered by the user.
#include <stdio.h>
int main(){
int i = 0;
char *last_word;
char str[800];
printf("enter:");
fgets(str,100,stdin);
while (str[i] != '\0') {
if (str[i] == ' ' && str[i + 1] > 32)
last_word = &str[i + 1];
i++;
}
/*------------------------these next lines of code-----------------------*/
/*-----> i = 0;
/*-----> printf( &last_word[i]);
return 0;
}