Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Get info from a text file in C


  • Please log in to reply

#1
BTPH

BTPH

    Member

  • 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

Cheers,
Ben

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

  • 0

Advertisements


#2
modernsavage

modernsavage

    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

#3
Swandog46

Swandog46

    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

#4
dsenette

dsenette

    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