Leespiker

Leecher
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Leespiker

  • Rank
    Newbie
  1. Google will answer most of your questions regarding fgets and how it works. Yes, it records \n, but I checked for this in the loop and didn't print it out. It is i >= 0 because you are iterating over the string (char array) from the last character in the string at index strlen(str) - 1 to the first character in the string at index 0. (I guess that 0 doesn't display either.) To enter a formatted code block, you just have to click the '<>' symbol above the text box. Let me know if you have any other questions. -Lee
  2. You should just iterate through the string backwards and print out each character one by one. #include <stdio.h> #include <string.h> #define N 35 int main(void) { char str[N]; int i; printf("Enter a sentence up to %d characters long: ", N); fgets (str, N, stdin); printf("Reversed sentence: "); for (i = strlen(str) - 1; i >= ; i--) { if (str[i] != '\n') { printf("%c", str[i]); } } printf("\n"); return ; } Let me know if you have any other questions. -Lee Edit: That's supposed to say return 0; at the end. I'm not sure why the 0 keeps disappearing.