/* paragrafo 1.9 pagina 27  esercizio 1.19
   prova la funzione reverse(s) che capovolge la stringa s
/*
#include <stdio.h>
#define MAXLINE 80

int getline(char line[], int maxline);
void reverse(char s[], int l);

int main()
{
    int len;
    char line[MAXLINE];
    
    printf("Dimensione buffer:%4d caratteri\n", MAXLINE);
    while ((len = getline(line, MAXLINE)) > 0) {
        reverse(line, len);
        printf("%s", line);
        if (line[len - 1] != '\n')
            putchar('\n');
    }
    return 0;
}

/*  getline: legge una riga in ingresso, la assegna a s, ne restituisce la lunghezza */
int getline(char s[], int lim)
{
    int c, i;
    
    for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i) {
        s[i] = c;
    }
    if (c == '\n') {
        s[i] = c;
        ++i;
    }
    s[i] = '\0';
    return i;
}

/*  reverse: capovolge la stringa s */
void reverse (char s[], int l)
{
    int i, j, temp;
    
    j = l - 1;
    if (s[j] == '\n')
        --j;
    for (i = 0; i < j; ++i, --j) {
        temp = s[i];
        s[i] = s[j];
        s[j] = temp;
    }
}