I working on a program that summerizes text documents and I need a way to find the length of the longest and shortest lines in the file and display it in a log file. I've already done a character count and line count. Also say I wanted to created different logfiles for each document i summerize how can this be achieved without overwriting the previos log file?
heres what i've done so far
int main (void)
{
char fname[128];
int c, nlines,avgchar=0;
int charctr= 0;
FILE *file;
do{
printf("Enter the name of a .TXT file:\n");
gets(fname);
file=fopen(fname,"r");
if(file==NULL)
{
printf("Cannot open file.\n");
return EXIT_FAILURE;
}
else
{
while ((c = fgetc(file)) != EOF)
{
charctr++;
nlines += c == '\n';
}
avgchar=charctr/nlines;
if((nlines<30)&&(avgchar<60))
{
printf("Error!!! file cannot be accepted!\n");
}
fclose(file);
file=fopen("summaryData.txt","w");
fputs("avgchar",file);
}
}while((nlines<30)&&(avgchar<60));
return 0;
}