Changing the contents of a file

luke1705 luke1705 is offline Offline 18 Days Ago, 9:41 pm |
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.
Quick reply to this message  
C Syntax
  1. /*
  2.  * This program is designed to open an existing file, lane9.txt,
  3.  * which has a collection of integers and characters. It then takes
  4.  * the characters out, leaving only the integers and spaces.
  5.  */
  6.  
  7. #include <stdio.h>
  8. int main ()
  9. {
  10. FILE* fp;
  11. fp = fopen("lane9.txt", "r");
  12. int i;
  13. int throw[i];
  14. int n = 20;
  15. if (fp == NULL)
  16. {
  17. printf("Error: file lane9.txt could not be opened\n");
  18. return 0;
  19. }
  20. for (i = 0; i < n; i++)
  21. {
  22. fscanf(fp,"%2d %*s", &throw[i]);
  23. }
  24. for(i=0;i<n; i++);
  25. {
  26. printf("%d ",throw[i]);
  27. }
  28. return 0;
  29. }

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC