UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » Reading files

#1 2007-06-17 09:24 PM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Reading files

Hello

I want to put into a struct three numbers from a text file
in which each number is in different line. I tested fgets() to read line by line, but i cant think an efficient way to read three integers each time
Thanks in advance

For example

struct nums
{ int x,y,z; }

nums1={1,2,3} nums2={4,5,6}

text file:
1
2
3
4
5
6

Offline

#2 2007-06-17 10:38 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Reading files

Don't go for efficient, go for clean and simple code.

So just use a loop and read them in one by one into an
array or something, and then copy it into the struct. Or
whatever.

Offline

#3 2007-06-17 10:57 PM

eusta
Member
Registered: 2006-12-13
Posts: 33

Re: Reading files

Offline

#4 2007-06-17 11:58 PM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Reading files

Can't you just use an existing library to read ppm files?

What array would be too large? You were talking about a
struct with three fields, so the array would be three fields too.

In this case it seems better to use an array instead of a struct
with some similar fields, that avoids some hassle it seems. Or
convert the file to binary first, and then do the real parsing.

It's a bit vague what your problem is, or what you try to achieve.

Offline

  • Index
  • » C
  • » Reading files

Board footer

Powered by FluxBB