Witam podczas sprawdzania mojego programu bot sprawdzający wywala mi taki oto błąd
Próba zamknięcia nieotwartego wcześniej pliku
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct file_t
{
FILE *f;
int size;
};
int open_file(struct file_t* f, const char *filename)
{
if(f==NULL || filename==NULL) return 0;
f->f = fopen(filename,"r+");
if(f->f==NULL)
{
return 0;
}
fseek(f->f,0,SEEK_END);
int x = ftell(f->f);
f->size=x;
fseek(f->f,0,SEEK_SET);
return 1;
}
struct file_t* find_min(const struct file_t* files, int size)
{
if(files==NULL || size <=0) return NULL;
int min=files->size;
int i=0,index=0;
for(i=0;i<size;i++)
{
if((files+i)->size<min)
{
min=(files+i)->size;
index=i;
}
}
return (struct file_t*)(files + index);
}
void close_file(struct file_t* f)
{
if(f==NULL) return;
fclose(f->f);
}
#define N 100
#define M 500
int main()
{
int licznik=0,x,i;
char name[N];
char tab[M];
struct file_t t[5];
printf("Podaj pliki \n");
while(licznik != 5)
{
fgets(name,N,stdin);
if(*name=='\n') break;
x=strlen(name);
if(*(name+x-1)=='\n') *(name+x-1)='\0';
if (fopen(name, "r") != NULL)
{
open_file(t+licznik, name);
licznik++;
}
}
if(licznik==0)
{
printf("Error");
return 1;
}
printf("co wpisac?\n");
struct file_t *wsk;
while (1)
{
fgets(tab, M, stdin);
if (*tab == '\n') break;
*(tab + strlen(tab) - 1) = '\0';
wsk = find_min(t, licznik);
fprintf(wsk->f, "%s\n", tab);
}
for(i=0;i<licznik;i++)
{
close_file((t+i));
}
return 0;
}
Czy znalazłby się ktoś miły i zlokalizowałby błędy w kodzie?