On Dec 7, 2:14*am, "Bill Cunningham" <nos...@nspam.invalid> wrote:
> * * I want to read formatted text from a text file into a function.
ITYM "...into an array"
> Would I
> use fscanf or fgetc.
dunno what you'd do. But I'd use fgets() followed by sscanf().
fscanf() is tricky to write the error handling and fgetc() you're
going to have to parse the input yourself. Another option for
converting numbers is strtol() et al.
> For example, I have a text file called "num" that says
> the following:
>
> 1 12.35
> 2 11.68
>
> I want to read this text, stored it and pass it as parameters to other
> functions. If I used fscanf I have no idea how to use the format specifiers
> since I don't really use the scanf family.
RTFM
> I usually use fgets to stdin for
> input and puts for writing. But this is to a file stream.
the "f" in fgets() stands for "file".
> I hope I'm making
> sense. Someone help me out with how reading with fscanf works. That's a new
> one on me.
you too idle to open a book? have you heard of the internet?
|