Ok, so I got a segmentation fault when I tried to run the program I created. I understand what this error means, but I don't know where it is. If someone can quickly look through my code and point it out that'd be great. BTW, the code isn't completely finished (ie the file to write on isn't being written on yet) but this doesn't effect this segmentation fault as far as I know.
I'm using Linux Red Hat to run the program and Emacs to compile it.
Syntax:
[CODE=c]void swap (float *a, float *b);
int main ( )
{
float diam[20], a, b;
int swap_count=0, n;
FILE *fptr1, *fptr2;
fptr1=fopen("a1 0.dat", "r");
fptr2=fopen("a1 2.txt", "w");
fscanf(fptr1,"% f", &diam[n]);
do
{
for(n=0; n<=19; n++)
{
diam[n]=a;
diam[n+1]=b;
if(a>b)
{
swap_count++;
void swap (float a, float b);
}
else
{
a=a;
b=b;
swap_count=0;
}
}
}while(swap_cou nt>=1);
printf("Diamete r=%f\n", diam[n]);
fclose (fptr1);
fclose (fptr2);
}
void swap (float *a, float *b)
{
float temp;
temp=*a; *a=*b; *b=temp;
}[/CODE]
I'm using Linux Red Hat to run the program and Emacs to compile it.
Syntax:
[CODE=c]void swap (float *a, float *b);
int main ( )
{
float diam[20], a, b;
int swap_count=0, n;
FILE *fptr1, *fptr2;
fptr1=fopen("a1 0.dat", "r");
fptr2=fopen("a1 2.txt", "w");
fscanf(fptr1,"% f", &diam[n]);
do
{
for(n=0; n<=19; n++)
{
diam[n]=a;
diam[n+1]=b;
if(a>b)
{
swap_count++;
void swap (float a, float b);
}
else
{
a=a;
b=b;
swap_count=0;
}
}
}while(swap_cou nt>=1);
printf("Diamete r=%f\n", diam[n]);
fclose (fptr1);
fclose (fptr2);
}
void swap (float *a, float *b)
{
float temp;
temp=*a; *a=*b; *b=temp;
}[/CODE]
Comment