Wow, I'm slipping. Someone beat me to the response quicker than I could write the code -(. Anyways, maybe something like the following...
Code:
#include <stdio.h>
#define MAXLINE 80
/*Rookie way to reverse a string*/
void reverse(char s[])
{
int i, j;
char temp;
i = 0;
while (s[i] != '\0')
++i;
--i;
if (s[i] == '\n')
--i;
j = 0;
while (j < i) {
temp = s[j];
s[j] = s[i];
s[i] = temp;
--i;
++j;
}
}
int getline(char s[], int max)
{
int c, i;
for (i = 0 ;i < max -1 && (c = getchar()) != EOF && c != '\n'; i++)
s[i] = c;
if (c == '\n') {
s[i++] = c;
}
s[i] = '\0';
return i;
}
int main(void)
{
char line[MAXLINE];
while (getline(line, MAXLINE) > 0) {
reverse(line);
printf("%s\n", line);
}
return 0;
}
[cd@localhost oakland]$ gcc -Wall -Wextra -Wshadow -ansi -pedantic easy.c -o easy
[cd@localhost oakland]$ ./easy
sex
xes
drugs
sgurd
chicks
skcihc
lalalalaliesoedosnomeosnffffffffffffffffffffffffff ffffffffffffffffffffffilolndodsmsoetssssssssssssss sssssssssssssssssssssssssssssssssssssssssiiiiiiii
odnlolifffffffffffffffffffffffffffffffffffffffffff fffffnsoemonsodeoseilalalalal
iiiiiiiissssssssssssssssssssssssssssssssssssssssss sssssssssssssteosmsd
maybe
ebyam
[cd@localhost oakland]$