473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

re: Newbie question: read .csv, .dat, and .txt file into 2 dimensional array

I just started to learn C. This is a very simple question, so please forgive me for posting this here.

I have a set of data in, let's say, .txt file. this txt file is in tab-delimited, like

1 4 9
2 6 10
3 7 11
4 8 12

Using fopen and while loop, I managed to print out the data line by line.

#include <stdio.h>
#include <stdlib.h>

int main()
{
FILE *fp;
char filename[80], ss[256];

printf("Filename=: ");
gets(filename);

if ((fp=fopen(filename,"r")) == NULL)
{
printf("Cannot open file.\n");
exit(1);
}

while (fgets(ss,256,fp) != NULL)
{
printf("%s",ss);
}


fclose(fp);

return 0;
}

What I would like to do as a first practice is compute the mean of each column. This data is recorded in x.xxx, so I should use double, right? So I would define

double mean(double x);

double arr[MAX_SIZE][MAX_SIZE];
int j,k;

and

double mean(double x)
{

double m;
for (k=1;k<=MAX_SIZE;k++)
{
m=data[][k]/MAX_SIZE;
std=
}
return m;
}

Is this right? I appreciate if someone could help. I just want to take advantage of compiler to shorten computing times as matlab takes a lot of time to process large data......

Thanks very much.

Taka
Apr 20 '07 #1
0 1127

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Fabian Wauthier | last post by:
Hi list, I am trying to dynamically grow a 2 dimensional array (Atom ***Screen) of pointers to a struct Atom (i.e. the head of a linked list). I am not sure if this is the right way to do it: ...
14
by: WStoreyII | last post by:
quick question i know that a two dimension array is like a chart basically (x columns, y rows) my question is though what would an array with more than two dimensions look like? would it...
3
by: HateSpam | last post by:
I am defining a class that has, as a member, an array of another user-defined class. private mBoard as CBoardPosition() The problem comes when I attempt to size the array, it should be an 8x8...
8
by: scythetleppo | last post by:
I am new thanks for the help. I have a text file set up like this: word1a<tab>word2a<tab>word3a<tab>word4a word1b<tab>word2b<tab>word3b<tab>word4b word1c<tab>word2c<tab>word3c<tab>word4c I...
14
by: John Gerrard | last post by:
Hi, my name is John and this is my first posting to comp.lang.c. I am learning C. I am a high school student with interest in programming. I have a copy of "The C programming language second...
9
by: Learner | last post by:
Hello , I am kinda new to VB 6.0. Is the line of code Private strCol(62, 2) As String declares a three dimensional array? Because in the code it is being used as strCol(1,0) = "x" strCol(2,0...
6
by: fniles | last post by:
I need to store information in a 2 dimensional array. I understand ArrayList only works for a single dimensional array, is that correct ? So, I use the 2 dimensional array like in VB6. I pass the...
2
by: ar30067 | last post by:
The 36 possible outcomes of rolling two dice. 7.18 What does the following program do? 1 // Ex. 7.18: Ex07_18.cpp 2 // What does this program do? 3 #include <iostream>
33
by: Adam Chapman | last post by:
Hi, Im trying to migrate from programming in Matlab over to C. Im trying to make a simple function to multiply one matrix by the other. I've realised that C can't determine the size of a 2d...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.