Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *ofp;
FILE *ifp;
int n, i, sum, input[100];
i = 0;
char numbers[][15] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};
char suite[][15] = {"Clubs", "Diamonds", "Hearts", "Spades"};
ofp = fopen("Result.dat", "w");
ifp = fopen("Cards.dat", "r");
if (ifp == NULL)
{
printf("Unable to open Cards.dat");
}
fscanf(ifp, "%d", &n);
while (n != 0)
{
input[i] = n - 1;
++i;
fscanf(ifp, "%d", &n);
}
sum = i;
for (i = 0; i < sum; i = i + 2)
{
fprintf(ofp, "%s of %s\n", numbers[input[i]], suite[input[i - 1]]);
}
return 0;
}
Not sure where it's getting this segmentation fault from...Any clues?