Kind Regards
Renato Parletta........
ICQ No: 13078952
is filed in a "Do Not File" file."
Senate Intelligence Subcommittee Hearing, 1975
-----Original Message-----Torbjørn Kristoffersen wrote:
From: holotko <[EMAIL PROTECTED]>
To: Linux C Programming <[EMAIL PROTECTED]>
Date: Wednesday, 7 October 1998 16:57
Subject: Re: Separate two integersI'm wondering how it is possible to read from a file looking like this:0001 1
0002 0
0003 0
0004 1The program should read the file and understand 0001 as an integer and 1 or
0 as an integer. The two numbers should be saved in variables such as a, b.Can anyone help?
T. Kristoffersen <[EMAIL PROTECTED]>
Yes, you can first open the file for reading via "fopen()" and then read the data into separate integer variables using "fscanf()" from the file stream. For example, the following example should set you in the right direction:/* readvals.c */
#include <stdio.h>
#include <stdlib.h>int main()
{
FILE fd;
int a, b;if ( !(fd = fopen( "numbers.dat", "r")) ) {
fprintf( stderr, "file error...\b");
exit(1);
}
do {
fscanf( fd, "%d" "%d", &a, &b);
printf("a = 000%d, b = %d \n", a, b); /* if you want to see the data displayed to stdout */
} while ( feof( fd ) == 0);exit(0);
}
You could also write fscanf() without the 2 sets of quotation marks as:
fscanf( fd, "%d %d", &a, &b);
-- email: [EMAIL PROTECTED] Local mailserver, remote OOP means programming