Hello,
I am facing problem writing an algorithm/codes. From a C program, I generated 100 data files, now I have to read those files having three columns each. Using every data of each line of all the 100 files I have to determine the average for all the three variables separately. Problem (again):
(1) Reading 100 data files
(2) There are three variables in every file whose calculated values are written in double format. Utilizing every data of each line, determine average. (in each line of 100 files, total 100 data points for every variable)
or
(3) is there any way to locate and read every data point in a data file.
It might be simple, I donot know. (I agree I'm not good at programming, but I'm trying) . If u donot understand it, plz let me inform.
Is there anybody who can support me regarding this issue (at least one part)? I'll be highly obliged.
Regards
Ahmed
3 2084
In order to read from the 100 different files, I'd create a loop (for loop). Inside the loop, I'd make a string for the file name (using the index as part of the name), open that file (if you are using std::string, you'll have to use the .c_str() function), and then process that file.
Now, inside the file, are you trying to find the average of the 3 numbers in each line? e.g. - FILE:
-
-
3.0 5.0 10.0 // average is 6.0
-
4.0 4.0 6.0 // average is 2.666...
or the average of all the numbers? e.g. - FILE:
-
-
3.0 5.0 10.0
-
4.0 4.0 6.0
-
// average is 5.333...
Hi,
Many thanks for suggestion. .c_str() is used for string as I know. Is it possible to use fscanf to read those 100 files which are named as peak1.dat to peak100.dat ? and at the same time, calculate average for every point of each line for 100 files?
By the way, dear members, I am not a computer engineer or programmer. I am a researcher on optical communication. For simulation I am using c language.
Ahmed
In order to read from the 100 different files, I'd create a loop (for loop). Inside the loop, I'd make a string for the file name (using the index as part of the name), open that file (if you are using std::string, you'll have to use the .c_str() function), and then process that file.
Now, inside the file, are you trying to find the average of the 3 numbers in each line? e.g. - FILE:
-
-
3.0 5.0 10.0 // average is 6.0
-
4.0 4.0 6.0 // average is 2.666...
or the average of all the numbers? e.g. - FILE:
-
-
3.0 5.0 10.0
-
4.0 4.0 6.0
-
// average is 5.333...
Yes, you'll be able to use fscanf to read in the numbers. You can either read them into an array or into 3 separate values and then find the average easily. What else do you have to do? Will you have to print this average value into the file? Do something else?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Olivier Maurice |
last post by:
Hi all,
I suppose some of you know the program Redmon (type redmon in google, first
result). This neat little tool allows to hook up any functionality to a
printer by putting the file printed...
|
by: Magnus |
last post by:
allrite folks, got some questions here...
1) LAY-OUT OF REPORTS
How is it possible to fundamentaly change the lay-out/form of a report in
access? I dont really know it that "difficult", but...
|
by: Erpman |
last post by:
I am trying to access the data with in a wav file. I am testing with very
small files in order to keep the code simple to start with.
Basically, im writing the entire wav file to a byte using a...
|
by: jccorreu |
last post by:
I've got to read info from multiple files that will be given to me. I
know the format and what the data is. The thing is each time we run
the program we may be using a differnt number of files,...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: Tyler |
last post by:
Hello All:
After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the...
|
by: blazedaces |
last post by:
Ok, so you know my problem, java is running out of memory reading with SAX, the event-based xml parser intended more-so than DOM for extremely large files. I'll try to explain what I've been doing...
|
by: swetha |
last post by:
HI Every1,
I have a problem in reading a binary file.
Actually i want a C program which reads in the data from a file which
is in binary format and i want to update values in it.
The file...
|
by: rka77 |
last post by:
Hi,
I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file -
Set : 1
Date:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |