Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/01/2011, 12:32
stiwi222
 
Fecha de Ingreso: noviembre-2009
Mensajes: 186
Antigüedad: 14 años, 7 meses
Puntos: 2
corregidme por favor

Buenas, he hecho este código teniendo en cuenta esta pregunta:

"Escribe un programa que imprima todas las lineas mayores de 80 caracteres que se le den"

y he hecho esto:
Código C:
Ver original
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #define MAXLINE 100
  5. #define MINLINE 80
  6.  
  7. int readline (char s[]);
  8.  
  9. int main() {
  10.    
  11.     char string[MAXLINE+1];
  12.     int len;
  13.    
  14.     while (strcmp(string, "quit\n") != 0) {
  15.          
  16.         len = readline(string);
  17.         if (len < MINLINE)
  18.             continue;
  19.            
  20.         else
  21.             printf("%s\n", string);
  22.         }
  23.     return 0;  
  24.    
  25. }
  26.  
  27. int readline (char s[]) {
  28.    
  29.     char c;
  30.     int i;
  31.    
  32.     for (i = 0; i < MAXLINE && (c = getchar()) != EOF && c != '\n'; i++)
  33.         s[i] = c;
  34.        
  35.     if (c == '\n') {
  36.         s[i] = c;
  37.         ++i;
  38.     }
  39.    
  40.     s[i] = '\0';
  41.    
  42.     return i;
  43. }

pero, ¿hay alguna manera mejor de hacerlo (sin cosas raras, estoy aprendiendo )?

y no es nada de ejercicios para clase ni nada de eso, soy autodidacta.

gracias :)