reading 1 dimensional data from an input file?? 
Author Message
 reading 1 dimensional data from an input file??

The following is a simple test program. What I want to do is read in a number from a file that have the format like this:

12.00
130.00
4.000
10000.000
100.00
1000.00

E-mail please. Thank you

                                         duc

/* test.c */
#include <stdio.h>
#include <varargs.h>
#define NT 6

main(argc, argv)
int argc;
char **argv;
{
    FILE *outfp, *infp;
    double T[NT];
    void errmsg();
    int t;

    if ((outfp = fopen(argv[2], "w")) == (FILE *)0)
      errmsg("printdata: cannot open output data file \"%s\"\n%s", argv[2]);

    if ((infp = fopen(argv[1],"r")) == (FILE *)0)
      errmsg("readata: cannot open input data file \"%s\"\n%s", argv[1]);

    for (t=0; t<NT; t++) fscanf(infp, "%f", &T[t]);
    for (t=0; t<NT; t++) printf("%lf\n", T);
    for (t=0; t<NT; t++) fprintf(outfp,"%lf\n", T[t]);
    fclose(infp);
    fclose(outfp);

Quote:
}

/*****************************************************************************/
void errmsg(va_alist)
int va_alist;
{
    va_list args;
    char *format;

    va_start(args);
    format = va_arg(args, char *);
    vfprintf(stderr, format, args);
    exit(1);

Quote:
}

/****************************************************************************/


Mon, 18 Apr 1994 21:56:42 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Reading file..Saving data in new file...

2. Movie/Sound files, reading data embedded with another file

3. Learning to read from an input file

4. Help: Reading Input Files using fget & strtok

5. Inputting data as text files.

6. how to read input from files

7. Learning to read an input file

8. Reading 2 lines from input file

9. HELP reading file input into variables

10. reading input from a file, help!!!

11. Need help with input data from file

12. reading input file problem

 

 
Powered by phpBB® Forum Software