0

I'm working on a program to score a bowling game. Right now, my terminal says that my program has a seg fault, but I can't tell where. Any other insight on how to help my program do what it's supposed to do would be helpful. I'm still not sure how to weed out all the characters, although I think my fscanf might do that.

/*
 *  This program is designed to open an existing file, lane9.txt,
 *  which has a collection of integers and characters.  It then takes
 *  the characters out, leaving only the integers and spaces.
 */

#include <stdio.h>
int main ()
{
FILE* fp;
fp = fopen("lane9.txt", "r");
int i;
int throw[i];
int n = 20;
if (fp == NULL)
{
	printf("Error: file lane9.txt could not be opened\n");
	return 0;
}
for (i = 0; i < n; i++)
{
	fscanf(fp,"%2d %*s", &throw[i]);
}
for(i=0;i<n; i++);
{
	printf("%d ",throw[i]);
}
return 0;
}
Votes + Comments
This is not a code snippet.
3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by mfaisalm
0

WaltP is write, That is 'i' is a local variable. It have a garbage value, It is very high.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.