All pastes #37663 Raw Edit

Untitled

public text v1 · immutable
#37663 ·published 2006-01-20 21:13 UTC
rendered paste body
#include <stdio.h>
#include <stdlib.h>

char *mreadline(FILE *desc) 
{
        char *line, *ptr;
        int i;
        line=ptr=(char*)malloc(11*sizeof(char));
        while(fgets(ptr, 11, desc)) 
        {
           for(i=0;i<10;i++) 
           {
              if(ptr[i]=='\n') 
              {
                 ptr[i]='\0';
                 return line;
              }
           }
           line=realloc(line, i+10);
           ptr=line+i+1;
        }
}

main()
{
    char s[11],k[5];
    char *l;
    printf("Podaj tekst: ");
    l=mreadline(stdin);
    
    printf("\nLOL: %s\n",l);
    free(l);
    getchar();
    
}