Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

58 lines (55 sloc) 1.054 kb
#include "bits.h"
char * fgetl(FILE *fp)
{
char * lout = (char *)malloc(81);
int i=0;
signed int c;
while(!feof(fp))
{
c=fgetc(fp);
if(c==EOF) // EOF without '\n' - we'd better put an '\n' in
c='\n';
if(c!=0)
{
lout[i++]=c;
if((i%80)==0)
{
if((lout=(char *)realloc(lout, i+81))==NULL)
{
printf("\nNot enough memory to store input!\n");
free(lout);
return(NULL);
}
}
}
if(c=='\n') // we do want to keep them this time
break;
}
lout[i]=0;
char *nlout=(char *)realloc(lout, i+1);
if(nlout==NULL)
{
return(lout); // it doesn't really matter (assuming realloc is a decent implementation and hasn't nuked the original pointer), we'll just have to temporarily waste a bit of memory
}
return(nlout);
}
int wordline(char *msg, int x)
{
char *ptr=strtok(msg, " ");
while(ptr)
{
x+=strlen(ptr)+1;
if((x>=width) && (strlen(ptr)<width))
{
printf("\n");
x=strlen(ptr);
}
else if(ptr!=msg)
{
printf(" ");
}
printf("%s", ptr);
ptr=strtok(NULL, " ");
}
return(x);
}
Jump to Line
Something went wrong with that request. Please try again.