S
Scott
Hi,
a problem with this following code is really bugging me.
tform = fopen(country, "r");
fseek(tform, 9L, SEEK_SET);
fgets(player2, 38, tform);
printf("Player Name (save): %s", player);
printf("Player Name (form): %s", player2);
fseek(tform, 10L, SEEK_CUR);
fgets(country2, 38, tform);
printf("Country Name (save); %s", country);
printf("Country Name (form): %s", country2);
fseek(tform, 18L, SEEK_CUR);
fscanf(tform, "%i \n", &app_budget);
fseek(tform, 16L, SEEK_CUR);
fscanf(tform, "%i \n", &hea_budget);
fseek(tform, 19L, SEEK_CUR);
fscanf(tform, "%i \n", &edu_budget);
fseek(tform, 18L, SEEK_CUR);
fscanf(tform, "%i \n", &sec_budget);
fseek(tform, 16L, SEEK_CUR);
fscanf(tform, "%i \n", &soc_budget);
fseek(tform, 17L, SEEK_CUR);
fscanf(tform, "%i \n", &eco_budget);
fseek(tform, 11L, SEEK_CUR);
fscanf(tform, "%i", &tax_change);
When I run the code as written above it will compile without errors,
but when I run the program I get a "Segmentation fault (core dumped)"
error. But, if I switch the country variable in the Fopen to
"Canada" (the value of the variable) it opens the file called Canada
fine and works perfectly. I know the variable is Canada as I had a
printf function write the value of the variable and it says "Canada".
To make things even more weird if I comment out all the above code
except the fopen with the variable it will not show the error. So, it
seems it can read the file, but can not do anything with it.
What I am trying to do is have a while loop that completes turns for a
PBEM. I have the while loop working great going though the list of
players one by one and stopping at the end of the file, but I need
this code above to load the turn sheet for each of the players. I
could use several "if"s to load the files, but that would mean I would
need to re-write the code and re-compile whenever I have a change in
players.
Any advice on how to fix this would be greatly appretiated. I am very
new to C and a all-round programming novice, so, please dum down any
help
--
Your friend,
Scott
Sent to you from a 100% Linux computer using Kubuntu Version 7.04
(Feisty Fawn)
a problem with this following code is really bugging me.
tform = fopen(country, "r");
fseek(tform, 9L, SEEK_SET);
fgets(player2, 38, tform);
printf("Player Name (save): %s", player);
printf("Player Name (form): %s", player2);
fseek(tform, 10L, SEEK_CUR);
fgets(country2, 38, tform);
printf("Country Name (save); %s", country);
printf("Country Name (form): %s", country2);
fseek(tform, 18L, SEEK_CUR);
fscanf(tform, "%i \n", &app_budget);
fseek(tform, 16L, SEEK_CUR);
fscanf(tform, "%i \n", &hea_budget);
fseek(tform, 19L, SEEK_CUR);
fscanf(tform, "%i \n", &edu_budget);
fseek(tform, 18L, SEEK_CUR);
fscanf(tform, "%i \n", &sec_budget);
fseek(tform, 16L, SEEK_CUR);
fscanf(tform, "%i \n", &soc_budget);
fseek(tform, 17L, SEEK_CUR);
fscanf(tform, "%i \n", &eco_budget);
fseek(tform, 11L, SEEK_CUR);
fscanf(tform, "%i", &tax_change);
When I run the code as written above it will compile without errors,
but when I run the program I get a "Segmentation fault (core dumped)"
error. But, if I switch the country variable in the Fopen to
"Canada" (the value of the variable) it opens the file called Canada
fine and works perfectly. I know the variable is Canada as I had a
printf function write the value of the variable and it says "Canada".
To make things even more weird if I comment out all the above code
except the fopen with the variable it will not show the error. So, it
seems it can read the file, but can not do anything with it.
What I am trying to do is have a while loop that completes turns for a
PBEM. I have the while loop working great going though the list of
players one by one and stopping at the end of the file, but I need
this code above to load the turn sheet for each of the players. I
could use several "if"s to load the files, but that would mean I would
need to re-write the code and re-compile whenever I have a change in
players.
Any advice on how to fix this would be greatly appretiated. I am very
new to C and a all-round programming novice, so, please dum down any
help
--
Your friend,
Scott
Sent to you from a 100% Linux computer using Kubuntu Version 7.04
(Feisty Fawn)