Ich bekomme Segmentierung Fehler beim Ausführen von Programm in Linux. Funktioniert gut in AIX.Segmentation Fault on fclose
Und ich seg Fehler mit der Meldung in gdb bekommen ...
Programm empfangene Signal SIGSEGV, Fehler Segmentation fclose @@ GLIBC_2.2.5() von /lib64/libc.so.6
<pre><code>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<time.h>
#include<sys/types.h>
#define _Monthly "99992016"
FILE *source,*list,*wlist,*movlist,*biflis;
char sf[85],sf1[85];
char filename[85],filename1[85],name[140],fstring[140],iname[140],account[85];
char *ptr="",*st="";
int i,len,x,y,z,BIF_COUNT,PIN_COUNT,YOUR_MONTHLY_COUNT,count1,count2;
char suffix[4]=".pin";
char *nptr=" ";
FILE *biflis;
int p;
int main()
{
long t;
system("ls -l|sort -n >test.txt");
system("cat test.txt|grep BH|awk '$5 <= 1610612736 {print $9}' > bhatia.out");
system("cat test.txt|grep BH|awk '$5 > 1610612736 {print $9}' > bhatia1.out");
if((list=fopen("bhatia.out","r"))==NULL)
{ printf("\n Error opening bhatia.out\n\n "); return 0; }
if((biflis=fopen("biffile_account.lis","w"))==NULL)
{ printf("\n Error opening biffile_account.lis file\n\n");
return 0; }
BIF_COUNT=0;
PIN_COUNT=0;
YOUR_MONTHLY_COUNT=0;
count1=0;
while((fgets(filename,85,list))!=NULL)
{
ptr=filename;
for(i=0;*ptr;i++,ptr++)
{
sf[i]=*ptr;
}i--;
sf[i]='\0';
if((source=fopen(sf,"r"))==NULL)
{
printf("\nError Opening Source File %s\n",sf);
return 0;
}
fseek(source,0,SEEK_END);
fseek(source,-90,SEEK_CUR);
while((fgets(name,140,source))!=NULL)
{
st=strstr(name,_Monthly);
count2=0;
if(st!=NULL)
{
YOUR_MONTHLY_COUNT++;
strcpy(account," ");
count2++;
//sprintf(fstring,"%s~%s",filename1,account);
}
count1= count2 + count1;
}
fclose(source);
if(count1 > 0)
{
printf(" %s GBIF file has the correct footer having ",sf,source);
printf(" %d number of correct bills \n",count1);
}
else
{
printf(" %s GBIF file has the footer missing and have incorrect bills \n",sf,source);
//printf(" %d number of in incorrect bills \n",count1);
}
count1=0;
BIF_COUNT++;
}
</code></pre>
Bitte minimieren Sie den problematischen Testfall und formatieren Sie ihn in etwas lesbares. – domen