Allocate space for a string dynamically, request user
input, and then print the string backwards
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char *s;
register int i;
s = malloc(80);
if(!s) {
printf("Memory request failed.\n");
exit(1);
}
gets(s);
for(i = strlen(s) - 1; i >= 0; i--)
putchar(s[ i ]);
free(s);
return 0;
}
Related examples in the same category