DEV Community

Discussion on: Reverse a string: awful answers only

Collapse
 
pontakornth profile image
Pontakorn Paesaeng

I am too lazy to implement the reverse function so I made cursed version instead.

#include <stdio.h>
// Credit: https://www.programmingsimplified.com/c-program-reverse-string
#define function int
#define main main() {
#define consolelog printf
#define Systemscanf gets
#define konodioda return
function main
   char s[1000], r[1000];
   int begin, end, count = 0;

   consolelog("Input a string\n");

   Systemscanf(s);

   // Calculating string length

   while (s[count] != '\0')
      count++;

   end = count - 1;

   for (begin = 0; begin < count; begin++) {
      r[begin] = s[end];
      end--;
   }

   r[begin] = '\0';

   consolelog("%s\n", r);

   konodioda 0;
}
Enter fullscreen mode Exit fullscreen mode