473,320 Members | 1,987 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,320 software developers and data experts.

Arrays for unknown amounts

For an assignment I have I need to make an array to hold the values of about 12000 lines of data. There are 4 columns of data but I only need the fourth. My teacher told the class to use this syntax to do this:

fscanf (infile, "%*s%*s%*s%f", &data_val[ i ] ) ;

The first three variables are suppressed and the fourth taken and put into the index. My question is how can I make a loop that will start indexing at the right place and continue to do that until there is none left. Here is my program thus far:

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

int main ( )
{
/*Opens files to be used*/

FILE *fptr1, *fptr2;
fptr1=fopen("a13.dat", "r");
fptr2=fopen("a13.txt", "w");

/*Declares variables*/

int n=0;
float dataval[12000], i;
char string1[14], buffer[256], string2[14];

/*Loop for displaying headers*/

while(string1[n]!=string1[17])
{
fgets (buffer, 256, fptr1);
puts (buffer);

fputs(buffer, fptr2);
n++;
}

/*Loop for reading in values*/

n=18;
while(string2[n]>=string2[18] && !feof(fptr1))
{
fscanf(fptr1, "%*s%*s%*s%f", &dataval[i]);
printf("%*s%*s%*s%f", dataval);
i++;
n++;
}


}

The first loop is to read in a header section that is 17 rows, and displays it to the screen and also writes it to a file. This loop works, it is the second loop I am struggling with.

Here is a sample of how the data is arranged:

"

"Source File: C:\PROGRA~1\PSLOG\195RIDE.PL1
"ID: IE Group 4 Bike Stress friday XR440 12 bi
"Ch1 lbl/scl: Start/Stop /A
"Ch2 lbl/scl: input voltage signal /-5.000 05.000
"Ch3 lbl/scl: Off /C
"Ch4 lbl/scl: Off /C
"Rate (mins): 0.0000833333324 Bat: 8.8
"First: Fri 20-Nov-1998 10:38:47am
"Last: Fri 20-Nov-1998 10:39:40am
"Transferred: Fri 20-Nov-1998 10:42:37am
"Eq. PC time: Fri 20-Nov-1998 10:42:38AM

"

Date,Time,Ch1:Deg F,Ch2:
11/20/1998 10:38:47.000 -4.989 0.238
11/20/1998 10:38:47.005 -4.989 0.231
11/20/1998 10:38:47.010 -4.989 0.228
11/20/1998 10:38:47.015 -4.989 0.231
11/20/1998 10:38:47.020 -4.989 0.228
Feb 4 '08 #1
1 1459
Here is the error I get when I try to compile the above program:

error: invalid types `float[12000][float]' for array subscript

I'm using Linux Red Hat to run the program.
Feb 4 '08 #2

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

Similar topics

10
by: Fabian | last post by:
Are there any speed issues in javascript with having really large arrays? I know if the array gets large enough, bandwidth and download time can be an issue, but does it take inordinate amounts of...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
0
by: PeterW | last post by:
I have a class which uses three other classes, two of which are used in arrays. This class is only ever used for incoming messages. All classes inherit from ISerializable and impliment...
31
by: Tomás | last post by:
When you have compile-time strings like: "The file is of unknown format." What kind of variables do you use to store it? At the moment I'm using: char const str = "The file is of unknown...
8
by: kd | last post by:
Newbie question here. It's been a while since I've done C programming, and I hit a wall last night. Let's say I have a three dimensional array, like so: int p = {{{0,0,0}, {1,1,1},...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.