Revision as of 20:56, 13 May 2024 by Admin (Created page with "One possible solution could be: <syntaxhighlight lang="C"> #include <stdio.h> #include <string.h> int main(void) { char s[81]; // A string of upto 80 chars + '\0' int i; puts("Please write a string: "); fgets(s, 81, stdin); puts("Your sentence in reverse: "); for (i= strlen(s)-1; i >= 0; i--) { if (s[i] == '\n') continue; // don't write newline else putchar(s[i]); } putchar('\n'); return...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Exercise


May 13'24

Answer

One possible solution could be: #include

  1. include

int main(void) { char s[81]; // A string of upto 80 chars + '\0'

   int i;
   
   puts("Please write a string: ");
   fgets(s, 81, stdin);
   puts("Your sentence in reverse: ");
   for (i= strlen(s)-1; i >= 0; i--)
   {
       if (s[i] == '\n')
           continue; // don't write newline
       else
           putchar(s[i]);
   }
   putchar('\n');
   return 0;

}

00