All pastes #423284 Raw Edit

Anonymous

public c v1 · immutable
·published 2007-04-04 01:17 UTC
rendered paste body
#include <stdio.h>#define MAXLINE 1000void reverse(char line[], int length);int getline(char line[], int max);void copy(char from[], char to[]);int main(){    char line[MAXLINE];    int len;    while ((len = getline(line, MAXLINE)))    {        reverse(line, len);        printf("%s", line);    }    printf("\n");    return 0;}/* reverse:  reverses the given line             of given length   Returns: Nothing                  */void reverse(char s[], int len){    int i;    --len; /* forget the silly \0 */    char temp[len];    copy(s, temp);   /* Copy the current line to a temporary space */    for(i = len; i >= 0; --i)        s[i] = temp[len - i];    /*  printf("%s %s", s, temp); */    return;}/* getline:  gets the current line   Returns: length of the line, limited to MAXLINE */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;        ++i;    }    s[i] = '\0';    return i;}/* copy:  copys "from" to "to" assuming          "to" is large enough   Returns: nothing                      */void copy(char from[], char to[]){    int i;    for(i = 0; (to[i] = from[i]) != '\0'; ++i);}