Ошибка шины (стек памяти сброшен на диск)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<ctype.h>


int main(int argc,char *argv[])
{
time_t clock;
int i,j,kol_vo, N,M;
char ch[300];
FILE *fin, *flog, *fout;
puts("######################################################################");

puts(" Format a text file. Paragraph indentation N spaces. MAX string length M characters");

puts("######################################################################");
puts("All actions of this program are recorded in the log.txt log");
puts("The output is in the out.txt file");
puts("The text file, protocol and output file are in the home directory");
puts("######################################################################");

if ((flog=fopen("log.txt","a"))==NULL)
{
puts("Protocol opening error !!!");
exit(0);
}
clock=time(NULL);
fprintf(flog,"%s:Protocol opened successfully\n",ctime(&clock));
clock=time(NULL);
if (argc<3)
{
puts("Error! Use ./text1 filename N M");
puts("Where filename is the name of the input file");
puts("Where M is the max line length N is the indentation");
clock=time(NULL);
fprintf(flog,"%s:Error opening input file\n",ctime(&clock));
clock=time(NULL);
fprintf(flog,"%s:Completed work\n",ctime(&clock));
fclose(flog);
puts("Hit Enter!");
getchar();
exit(0);
N=atoi(argv[2]);
M=atoi(argv[3]);
}

if(N<3 || N>10) N=8;
if(M<30 || M>100) M=60;
fprintf(flog,"%s:Data entered incorrectly\n");

if ((fin=fopen(argv[1],"r"))==NULL)
{

clock=time(NULL);
fprintf(flog,"%s:Error opening input file %s\n",ctime(&clock),argv[1]);
fclose(flog);
puts("Error opening input file");
exit(0);
}
else
{
clock=time(NULL);
fprintf(flog,"%s:Input file %s opened successfully\n",ctime(&clock),argv[1]);
}
if ((fout=fopen("out.txt","w"))==NULL)
{
clock=time(NULL);
fprintf(flog,"%s:Error opening output file\n",ctime(&clock));
puts("Error opening output file");
exit(0);
}
else
{
clock=time(NULL);
fprintf(flog,"%s:Output file opened successfully\n",ctime(&clock));
}
while (!feof(fin))
{
fgets(ch,298,fin);
clock=time(NULL);
kol_vo=strlen(ch);j=0;
if(strncmp(ch," ",3)==0){j=N;
for(i=1;i<=N-3;i++)
fprintf(fout," ");}


for(i=j;i<kol_vo;i++)
{fprintf(fout,"%c",ch[i]);if(((i%M)==0)&&i!=0)fprintf(fout,"\n");}




}



fprintf(flog,"%s:- out.txt\n",ctime(&clock),ch);
fclose(fin);
clock=time(NULL);
fprintf(flog,"%s:Input file closed\n",ctime(&clock));
fclose(fout);
clock=time(NULL);
fprintf(flog,"%s:Input file closed\n",ctime(&clock));
clock=time(NULL);
fprintf(flog,"%s:Completed work\n",ctime(&clock));
fclose(flog);
puts("Hit Enter!");
getchar();
exit(0);
}

Ответы (1 шт):

Автор решения: Sergey

Ну, навскидку. В строке 51:

fprintf(flog,"%s:Data entered incorrectly\n");

у Вас нет переменной для символа форматирования %s

→ Ссылка