Thread: savegame file i/o help

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    scanf awaits a pointer to variable to store data in it

    use &hp when you passig your variable to scanf
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 09:35 AM
  2. File I/O Assertion Failure in VS2008
    By clegs in forum C Programming
    Replies: 5
    Last Post: 12-25-2008, 04:47 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02: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, 05:56 AM