2 Replies - 230 Views - Last Post: 01 June 2012 - 03:59 PM Rate Topic: -----

#1 irwin08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 04-March 12

Saving ints and strings to a file in C not C++

Posted 01 June 2012 - 03:06 PM

Hi i am making a game and i want the person to be able to save the game. So I need to stick all the variables in a single file. the file will look something like this once i write everything to it:

hello
jesse
yes
house
1
5
3
9
7


and so on... Is there a way to specify which line i want read with fscanf? I am using both int's and char* 's. thx
Is This A Good Question/Topic? 0
  • +

Replies To: Saving ints and strings to a file in C not C++

#2 irwin08  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 04-March 12

Re: Saving ints and strings to a file in C not C++

Posted 01 June 2012 - 03:31 PM

Sorry I meant taking strings and ints out of a file and assigning them to variables that are already made. I wasn't that clear
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

Re: Saving ints and strings to a file in C not C++

Posted 01 June 2012 - 03:59 PM

Quote

Is there a way to specify which line i want read with fscanf?


No, for a text file you read each line (and ignore what you read from the ones you don't care about) until you reach the one you want.

If the data is in a fixed format, then you could consider using a struct, like this:

struct person
{
    char first_name[40];
    char last_name[40];
    int age;
};


and then load and save it from and to a binary file.

http://www.codinguni...-binary-file-io
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1