I am trying to create a switch function...this is what I have so far:
switch (fixed)
{
case(1): {
fp1 = fopen("somefile.dat", "w");
printf("\"somefile.dat\"");
while(l<6)
{
for (ctr=(l*10); ctr<((l+1)*10); ctr++)
{fprintf(fp1," %d,", deck[ctr]);}
fputs("\n", fp1);
l++;
}
break;
}
case(2): {
fp2 = fopen("otherfile.dat", "w");
printf("\"otherfile.dat\"");
while(l<6)
{
for (ctr=(l*10); ctr<((l+1)*10); ctr++)
{fprintf(fp2, " %d,", deck[ctr]);}
fputs("\n", fp2);
l++;
}
break;
}
default: break;
But for some reason, when I run this witha menu I have created I get a segmentation error when I choose fixed to be 1. When fixed is 2 it works just fine. I get my file no problems. I have all the variables [fixed, l, and fp1, & fp2] defined, and I have all the closing stuff [return, and fclose]. Could someone give me some help please?
-rewclaus
switch (fixed)
{
case(1): {
fp1 = fopen("somefile.dat", "w");
printf("\"somefile.dat\"");
while(l<6)
{
for (ctr=(l*10); ctr<((l+1)*10); ctr++)
{fprintf(fp1," %d,", deck[ctr]);}
fputs("\n", fp1);
l++;
}
break;
}
case(2): {
fp2 = fopen("otherfile.dat", "w");
printf("\"otherfile.dat\"");
while(l<6)
{
for (ctr=(l*10); ctr<((l+1)*10); ctr++)
{fprintf(fp2, " %d,", deck[ctr]);}
fputs("\n", fp2);
l++;
}
break;
}
default: break;
But for some reason, when I run this witha menu I have created I get a segmentation error when I choose fixed to be 1. When fixed is 2 it works just fine. I get my file no problems. I have all the variables [fixed, l, and fp1, & fp2] defined, and I have all the closing stuff [return, and fclose]. Could someone give me some help please?
-rewclaus