divide first column numbers 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <fstream>

int main()
{
    std::ifstream in_file("in.dat");
    std::ofstream out_file("out.dat");
    
    do {
        double x1, x2, x3, x4;
        in_file >> x1 >> x2 >> x3 >> x4;
        out_file << (x1 / 600) << " " << x2 << " " << x3 << " " << x4 << "\n";
    } while (in_file.good() && out_file.good());
}
Last edited on
an other question.... is any function that calculate an integrala? Because the magnitude of signal is defined with an integrala and whit out file I must calculate an A
Afaik, there is no direct implementation in the standard. But if you look for a while you will find some in the net. In fact, it isn't so difficult to write his own integral function. There are many numerical approximations like simpson formula, that gives you the algorithm you need.

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

pointer_fisier2=fopen("datepout.txt","w");
if ((pointer_fisier = fopen("peter6.txt", "r")) == NULL)
printf("Error opening peter6.txt for input\n");
do{ //ciclu cu test final do..while
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(pointer_fisier));
fclose(pointer_fisier);
fclose(pointer_fisier2);
printf("\n Done!!!");getch();
}


Just remembet the c... under linux I get some err on C++ ....
Topic archived. No new replies allowed.