savegame file i/o help

This is a discussion on savegame file i/o help within the C Programming forums, part of the General Programming Boards category; hey i need to load the contents of a file in this format Code: 1 0 0 0 5 30 ...

  1. #1
    Registered User aaron11193's Avatar
    Join Date
    Oct 2006
    Posts
    13

    Exclamation savegame file i/o help

    hey i need to load the contents of a file in this format
    Code:
    1
    0
    0
    0
    5
    30
    into several variables..
    i got the saving working properly.
    i have this code but it doesnt work
    Code:
    int load_game( void ){
    	FILE *savegame;
    	int battle_num = 0;
    	int awake;
    	int hp = 30;
    	int att = 5;
    	int def = 5;
    	int spd = 5;
    	int power = 5;
    	int wins = 0;
    	int loses = 0;
    	int cash = 100;
    	savegame = fopen("streetfighting.sav", "r");
    	if( savegame == NULL ){
    		printf("\n\nNo previously saved game...\n\n");
    		main();
    	}else{
    		fscanf( savegame, "%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d\n%d", hp, att, def, spd, power, cash, wins, loses, awake, battle_num );
    		printf("\n\n...LOADED...\n\n");
    		menu( hp, att, def, spd, power, cash, wins, loses, awake, battle_num );
    	}
    }
    thx

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    scanf awaits a pointer to variable to store data in it

    use &hp when you passig your variable to scanf
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001
    Posts
    768
    Quote Originally Posted by vart
    scanf awaits a pointer to variable to store data in it

    use &hp when you passig your variable to scanf
    I agree with vart, the fscanf function is very similar to the scanf function.
    "I don't suffer from insanity but enjoy every minute of it" - Edgar Allen Poe

    http://www.Bloodware.net - Developing free software for the community.

  4. #4
    Registered User aaron11193's Avatar
    Join Date
    Oct 2006
    Posts
    13
    thanks it works fine now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 03:47 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. 2 questions surrounding an I/O file
    By Guti14 in forum C Programming
    Replies: 2
    Last Post: 08-30-2004, 11:21 PM
  5. advice on file i/o
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-29-2001, 04:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21