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
10 replies to this topic
#1
Posted 09 April 2010 - 11:36 PM
|
|
|
#2
Posted 10 April 2010 - 05:32 AM
What part of it are you having trouble with? Dividing by 600, reading a file, writing a file, something else?
#3
Posted 10 April 2010 - 05:43 AM
How to write that program will depend on if you want C or C++.
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#4
Posted 10 April 2010 - 06:01 AM
Ancient Dragon said:
How to write that program will depend on if you want C or C++.
in C :)
some reason don't read the fille.... output is 0000 0000 0000 on all line....
#5
Posted 10 April 2010 - 06:56 AM
Where is your code ? Sorry, but I'm not able to see your monitor.:cursing:
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.
#6
Posted 10 April 2010 - 09:18 PM
Ancient Dragon said:
Where is your code ? Sorry, but I'm not able to see your monitor.:cursing:
#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());
}
Edited by ZekeDragon, 12 April 2010 - 03:08 AM.
Please use [code] tags (the # button) when posting code.
#7
Posted 10 April 2010 - 10:21 PM
balambur said:
#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());
}
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());
}
Is this your C program.. cool.. Its C++ dude...
you program works fine.. What's the problem..
#8
Posted 12 April 2010 - 02:24 AM
#include <stdio.h>
#include <conio.h>
void main(void)
{
FILE *pointer_fisier;
FILE *pointer_fisier2;
int t,x,y,z,c;
if ((pointer_fisier = fopen("peter6.txt", "r")) == NULL)
printf("Error opening peter6.txt for input\n");
else
{
fscanf(pointer_fisier, "%d %d %d %d", &t, &x, &y, &z);
c=t/600;
pointer_fisier2=fopen("datepout.txt","w");
fprintf(pointer_fisier2, "t %d x %d y %d z %d",c,x,y,z);
fclose(pointer_fisier);
fclose(pointer_fisier2);
}
}
how can I cicle until EOF??? I know that is in C++ :D
now is in c and the problem is under ubuntu linux don't work so well in c++ so I need c
Edited by ZekeDragon, 12 April 2010 - 03:07 AM.
Please use [code] tags (the # button) when posting code.
#9
Posted 12 April 2010 - 05:18 AM
C++ works fine under ubuntu. conio, however is NOT cross-platform.
#10
Posted 19 April 2010 - 03:37 AM
Ancient Dragon said:
Where is your code ? Sorry, but I'm not able to see your monitor.:cursing:
That is hilarious. lol.
But, seriously, you should work on your telepresence skillz.
#11
Posted 19 April 2010 - 10:56 AM
try this function that i just wrote in C, there might be some errors ...
[SIZE=3][FONT=Courier New]char * read_line(FILE * fp)
{
int counter = 0;
char * line = 0;
char * buffer = (char*) malloc(4096+1);
char c = 0;
if(fp == 0) return 0;
while((c = fgetc(fp)) != EOF && c != '\n')[/FONT][/SIZE] [SIZE=3][FONT=Courier New]buffer[counter++] = c;[/FONT][/SIZE][SIZE=3][FONT=Courier New]
[/FONT][/SIZE][SIZE=3][FONT=Courier New] if(counter < 4096)[/FONT][/SIZE]
{
[SIZE=3][FONT=Courier New] line = (char*) malloc(counter);
[/FONT][/SIZE][SIZE=3][FONT=Courier New] for(int i=0; i<counter; i++) line[i] = buffer[i];
buffer[counter] = '\0';
[/FONT][/SIZE]}
[SIZE=3][FONT=Courier New]
return line;[/FONT][/SIZE]
[SIZE=3][FONT=Courier New]}
[/FONT][/SIZE]
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









