divide first column from a txt file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balambur
    New Member
    • Apr 2010
    • 2

    divide first column from a txt file

    hy guys,
    I am a beginner in c and from 3 days I have a big question...
    I have a file containing the folowing data:
    5971 -44 976 -23
    5981 -53 980 -23
    5991 -50 978 -21
    6001 -56 975 -21
    6011 -58 971 -21
    6021 -52 981 -24
    6031 -49 974 -22
    6041 -50 981 -31
    6051 -47 978 -37
    6061 -42 978 -38
    6071 -37 977 -42
    I need to divide the first column by 600 to convert in to seconds and write it out into a new file first column divided and the second, 3'th, 4'th leave it like is it now....
    can anyone help me?
    please???
    Thanx a lot
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    I know this sounds like buck passing but why don`t you rewrite the file with an extra field populated by col_1/600........then refer to this field direct

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      Also, how did you want the column formatted? Did you want only whole seconds, or decimals to the tenth?

      Comment

      • balambur
        New Member
        • Apr 2010
        • 2

        #4
        #include <stdio.h>
        #include <conio.h>
        void main(void)
        {
        FILE *pointer_fisier ;
        FILE *pointer_fisier 2;
        int t,x,y,z,c;

        pointer_fisier2 =fopen("datepou t.txt","w");
        if ((pointer_fisie r = fopen("peter6.t xt", "r")) == NULL)
        printf("Error opening peter6.txt for input\n");
        do{
        fscanf(pointer_ fisier, "%d %d %d %d", &t, &x, &y, &z);
        c=t/600;
        fprintf(pointer _fisier2, "\n t = %4d \t x = %4d \t y = %4d \t z = %4d",c,x,y,z);
        }while(!feof(po inter_fisier));
        fclose(pointer_ fisier);
        fclose(pointer_ fisier2);
        printf("\n End!!!");getch( );
        }



        this is it... I must take a book and remember some c but it is working now...

        Comment

        Working...