- #1
chasely
- 2
- 0
Hello all, I'm having a very frustrating time with this piece of code. For some reason, I can't seem to open the file I'm trying to read data in from. This piece of code works in everything I've tried, except xCode. This wouldn't bother me, but I really only use my laptop for coding, so I need it to work in xCode.
The debugger stops at the fopen command line, like it can't find the file.
If any of you can give me any help I would really appreciate it. I've included the original code and a screenshot of the XCode setup.
The debugger stops at the fopen command line, like it can't find the file.
If any of you can give me any help I would really appreciate it. I've included the original code and a screenshot of the XCode setup.
/*
What is wrong with this in xcode?
*/
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main() {
FILE *fp;
int tokens;
int wager;
int CompDie;
int UserDie;
fp = fopen ("data.txt","r");
srand((int)time(NULL) + 1);
fscanf (fp, "%d", &tokens);
printf ("%d", tokens);
fclose (fp);
printf ("Description\n");
printf ("What is your wager\n");
scanf ("%d", &wager);
UserDie = (rand() % 6) + 1; /* produce a random number 1 to 6 */
CompDie = (rand() % 6) + 1; /* what is the % used for? */
printf ("User: %d Computer: %d", UserDie, CompDie);
if (UserDie > CompDie)
tokens = tokens + wager;
if (CompDie > UserDie)
tokens = tokens - wager;
printf ("Tokens left: %d", tokens);
fp = fopen ("data.txt","w");
fprintf (fp, "%d", tokens);
fclose (fp);
return 0;
}