segmentation fault in following peice of code :please help
hi
segmentation fault in foll code is driving me nuts..
i am basically reading an ascii file in which nums are stored seperated by commas
i manipulate these numbers and store in another ascii file
please help ,this code is vital to working of my project to be submiited by monday 23rd march
when i ran gdb it told that the foll code caused the segmentation fault
number+=(num[lnum]*pow(10,lnum))
the whole prg is listed below
code..
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
FILE*ascii;
FILE *ascii2;
double data;
char c;
int i=0,flag=0,numcomma=0,lnum,sign,j=0;
double number=0;
char num[5];
ascii=fopen("/home/shobhit/das/tempo-1.1.4/fft/comma.ascii","r");
ascii2=fopen("/home/shobhit/das/tempo-1.1.4/fft/newline4.txt","w");
while (!feof(ascii))
{ j++;
if(j>5)
break;
if(c==','&&numcomma==2){
lnum=i;i=0;flag=1;//beginning of new num
}
if(lnum&&!i)
{number=0;
if(num[0]=='-')
{sign=-1;lnum-=2;}
else {sign=1;lnum=lnum-1;}
for(;lnum>=0;lnum--){
number+=(num[lnum]*pow(10,lnum));}//this line gives the segmetation fault
if(sign==-1)
number*=-1;
data=(number+2048)*0.09645-199;
fprintf(ascii2,"%lf ",data);
}
c=getc(ascii);
if(flag==1)
{ if(c==',')break;//for 2nd comma ie ,123,
num[i]=c;
i++;}
if(c==',')
{ flag=1;numcomma++;}
}
fclose(ascii);
fclose(ascii2);
return 0;
}
thanks
linorg
|