Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Get info from a text file in C

  • Please log in to reply




  • Member
  • PipPipPip
  • 167 posts
Okay i need to put five numbers in a .txt file, say for example
14, 26, 19, 28, 7
then i need to write a proggram in C that will read those numbers and perform various calculations to them, is there a way to get the computer to say first number=a second number=b, third number=c, etc.? or is it more complicated than that, also the numbers should be on one line of the.txt file

any help would be much appreciated


Edited by BTPH, 05 October 2005 - 04:58 PM.

  • 0




    Retired Staff

  • Retired Staff
  • 51 posts
The simplest way would be to write the numbers to a INI file. There are Windows API functions which you can call to read and write the values. Lookup GetPrivateProfileInt.
  • 0



    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP
That's not at all the simplest way. Use fscanf. If the numbers are all stored on one line, delimited by commas like your example, try:

fscanf(f, "%d,", &number);

where f is a FILE * pointer to an open file handle, and &number is the address of an integer variable number that you have already declared.
  • 0



    Je suis Napoléon!

  • Community Leader
  • 26,047 posts
  • MVP
i'm not the best with c...but i would say that having it as a comma deliniated file will make that text file into a very basic database...you should look through your "c" books for comma seperated variables, or format...not sure what the last word would be...but look for comma seperated
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP