Here's some code I wrote...Use it for reference.
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
int N, x;
char fname[21];
printf("Enter the filename: ");
scanf("%s", fname);
//Open
fp = fopen(fname, "r");
//If no file
if (ifp == NULL)
{
printf("Error, %s not available\n", fname);
exit(1);
}
int scores[22];
int i, cc;
char ss;
i = 0;
//Array storage
fscanf(ifp, "%c", &ss);
while(ss != '-')
{
if(ss == 'X')
{
cc = 10;
scores[i] = cc;
i = i + 1;
}
else if(ss == '/')
{
cc = 10 - scores[i-1];
scores[i] = cc;
i = i + 1;
}
else if(ss >= '0' && ss <= '9')
{
cc = ss - '0';
scores[i] = cc;
i = i + 1;
}
fscanf(ifp, "%c", &ss);
}
scores[i] = -1;
int howmany,sum;
howmany = i;
sum = 0;
//Prints SUM
printf("N = %d\n", howmany);
i = 0;
while(scores[i] != -1)
{
sum = sum + scores[i];
i++;
}
printf("SUM: %d\n",sum);
printf("----------------------\n");
int f,e,total,y;
y = 0;
e = 0;
total = 0;
//Scores total with strike, spare rules
for (y=0;y<22;y++)
{
if(scores[e] == 10)
{
total = total + 10 + scores[e+1] + scores[e+2];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 1;
printf("STRIKE!\n");
}
else if(scores[e] + scores[e+1] == 10)
{
total = total + 10 + scores[e+2];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 2;
printf("SPARE!\n");
}
else if(scores[e] == -1)
{
printf("----------------------\n");
printf("Your final score is: %2d", total);
break;
}
else
{
total = total + scores[e] + scores[e+1];
printf("Frame %2d: Total %2d\n",y+1, total);
e = e + 2;
}
}
return 0;
}
Here is the file it reads from...Use it for formatting references.
Code:
X X X X X X 9 / 9 / 9 / 9 / -1
Let me know if this helps...