All pastes #17304 Raw Edit

Miscellany

public text v1 · immutable
#17304 ·published 2005-07-09 08:58 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

#define ENTER '\n'
#define MAX_LINE 100

int get_len(char *str) {
    int cnt;
    char *s;
    
    cnt = 0;
    for (s=str; *s; s++)
        cnt++;
        
    return (cnt);
}

int get_line(char *line, int n) {
    char c;
    int cnt;

    fflush(stdin);
    cnt = 0;
    while ((c = getchar()) != ENTER && cnt < n) {
        line[cnt++] = c;
    }
    if (cnt != 0) line[cnt] = '\0';

    return cnt;
}

void print_inverse(char *line) {
    int i;
    
    for (i=get_len(line)-1; i>=0; i--) {
        printf("%c", line[i]);
    }
}

int main(int argc, char *argv[])
{
    char line[MAX_LINE];
    
    get_line(line, MAX_LINE);
    print_inverse(line);
    
    system("PAUSE");
    return 0;
}