I am having trouble reading in just a single data point from a file. It is supposed to be able to read two columns of data (such as x and y values), but I found out my code cannot even read a single value of double precision. Any help would be appreciated.
The file is at D:\test.txt
and there is a single value of 1.11111.
Enter the location of file (text file) of the airfoil coordinates: D:\test.txt
There are 1 lines
The amount of data in x and y is 1 points and 1 points.
failed to read.
* Process returned 1 *
Press any key to continue...
That was my input.
/*
Purpose:
Create a program that can take in a list of data points that represents an airfoil from some file.
Then through the use of spline function, spline the data points for interpolation then go on to plotting them.
With these data points, use the Vortex Panel Method to obtain coefficients of lift, pressure, and tangential velocity.
Then after these are calculated, plot each with respect to the splined x data points.
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <stdlib.h>
#define LEN 12
int countlines(FILE *fp);
int main (void)
{
char airfoil[500];
double *x_data = NULL;
double *y_data = NULL;
FILE *pfile = NULL;
int line_count = 0;
double test = 0.0;
printf("Enter the location of file (text file) of the airfoil coordinates: ");
scanf("%s", airfoil);
if(fopen_s(&pfile, airfoil, "r"))
{
printf("Error opening the file for reading the data. Program terminated.\n");
exit(1);
}
line_count = countlines(pfile);
printf("There are %d lines\n", line_count);
x_data = realloc(x_data, line_count*(sizeof(double)));
y_data = realloc(y_data, line_count*(sizeof(double)));
if((!x_data) || (!y_data))
{
printf("Memory allocation has failed. Exiting...\n");
exit(1);
}
printf("The amount of data in x and y is %zu points and %zu points.\n", (sizeof(x_data)/sizeof(double)), (sizeof(y_data)/sizeof(double)));
if(EOF == fscanf_s(pfile, "%lf", &test))
{
printf("failed to read.\n");
exit(1);
}
//for(int i = 0; i < line_count; i++)
//{
//fscanf(pfile, " %lf", &x_data[i]);
//}
printf("The x-data are %lf!\n", test);
//for(int i = 0; i < line_count; i++)
//{
//printf("%.2lf", x_data[i]);
//printf("\n");
//}
return 0;
}
int countlines(FILE *fp)
{
int lines = 0;
char str[LEN];
while(!feof(fp))
{
if (fgets(str, LEN, fp) != NULL);
{
lines++;
}
}
return lines;
}
countlines just brought the file pointer to the end of file. Before you can read anything, you must first rewind the file to the beginning:
fseek(pfile,0,SEEK_SET);
You can do ths in countlines().
See also the comments, that spot some more errors.
Related
Write code that reads a number of values, interpreted as integers, from a file named “mtData.txt”, where the first number tells how many subsequent numbers there are, and there will never be more than 100 integers.
I'm new to C, coming from a background in Java. I wrote the following, producing an infinite loop that prints the obvious statements and an address not the values from the file.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(){
FILE *fp = (FILE*) 0;
int c = -1;
fp = fopen("myInput.txt", "r");
if(fp == NULL){
puts("Error accessing file");
return(-1);
}
bool doneReading = false;
int numbers[100];
while (!doneReading){
puts("Reading now");
c = fscanf(fp, "%d", numbers);
printf("Read %d items\n", c);
if(feof(fp)){
doneReading = true;
}
printf("%d\n", numbers);
fclose(fp);
}
}
A possible approach (take a look at how the loop is implemented):
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void) {
FILE* fp = fopen("myInput.txt", "r");
if (fp == NULL) {
puts("Error accessing file");
return 1;
}
// this is the array that will contain the numbers
int numbers[100];
// this is the number of integers that the file contains
int max_numbers;
// this is the number of integers that we have actually read from the file
int counter = 0;
// max_numbers is actually the first integer that we find in the file
if (fscanf(fp, "%d", &max_numbers) != 1 || max_numbers < 0 || max_numbers > 100) {
printf("ERROR\n");
return 1;
}
printf("Max numbers: %d\n", max_numbers);
// now that we know the number of integers, we can loop to read them all
while (counter < max_numbers) {
if (fscanf(fp, "%d", &numbers[counter]) != 1) {
printf("ERROR\n");
return 1;
}
counter += 1;
}
// now we print all the numbers that we have read
for (int i = 0; i < counter; i += 1) {
printf("Number #%d = %d\n", i, numbers[i]);
}
fclose(fp);
return 0;
}
I used fscanf(fp, "%d", &var) != 1 to put the number inside var and check that everything went well (fscanf() will return the number of arguments successfully assigned, in this case only %d).
EDIT:
The previous code does not check if the file contains more data than necessary (that would also mean that the file is not valid), so it just ignores that extra data (thanks #chux for pointing it out).
Also note that fscanf() will not detect integer overflows, so in the future you may want to look at alternative approaches for integer parsing (e.g.: strtol()).
I'm trying to use the libsndfile library to read/write information between audio files.
I've managed to read the original file, write a copy of it with "watermark" values.
All I'm trying to do now is print any index where the value is not 0.
However, when I call my printBuffer() function, it's returning all 0s even though when on debug mode, I can see that the values in buffer are not zero/changing each iteration.
Am I calling the buffer array incorrectly?
I'm still new to C so if you have any suggestions they would be greatly appreciated.
Thank you.
Code:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <stdlib.h>
#include <sndfile.h>
#include <time.h>
#define MAX_CHANNEL 2
#define BUF_SIZE 1024
int numItems(int frames, int channels);
void printInfo(int frames, int channels, int sampleRate);
void watermark(double *buffer, int count, int channels);
void watermark2(double *buffer, int count);
void readFile(int fileNumber);
void printBuffer(double *buffer, size_t count);
int main(void)
{
int chosenFile, answer;
printf("Please select the file you want to read\n");
printf("1. File1\n");
printf("2. File2\n");
printf("3. File3\n");
printf("4. File4\n");
printf("5. File5\n");
scanf("%d", &chosenFile);
processFile(chosenFile);
/*
Put boolean here to check whether to process the original file or the new one
*/
printf("Would you like to read the new file?\n");
printf("1. Yes\n");
printf("2. No\n");
scanf("%d", &answer);
if (answer == 1)
{
readFile(chosenFile);
}
}
int processFile(int fileNumber)
{
/*READING FILE*/
static double buffer[BUF_SIZE];
SF_INFO info;
SNDFILE *infile,*outfile;
int readCount, i;
/*
Put boolean here to check whether it should read the original files, or the new output files
*/
char *Files[] = { "File1.wav", "File2.wav", "File3.wav"
, "File4.wav", "DFile5.wav" };
char *Files2[] = { "File1Output.wav", "File2Output.wav", "File3Output.wav"
, "File4Output.wav", "File5Output.wav" };
char *inputFile = Files[fileNumber - 1];
if (!(infile = sf_open(inputFile, SFM_READ, &info)))
{
printf("Not able to open input file %s.\n", inputFile);
puts(sf_strerror(NULL));
return 1;
};
printf("You have opened: %s\n", Files[fileNumber - 1]);
printInfo( info.frames, info.channels, info.samplerate);
int num = numItems(info.frames, info.channels);
printf("Buffer(frames*channels): %d \n", num);
/*WRITING FILE*/
char *outputFile = Files2[fileNumber - 1];
printf("Your file has been saved in the following location: %s\n", outputFile);
if (!(outfile = sf_open(outputFile, SFM_WRITE, &info)))
{
printf("Not able to open output file %s.\n", outputFile);
puts(sf_strerror(NULL));
return 1;
};
/*
Actual buffer size is numItems, somehow can't declare buffer as buffer[numItems]
BUF_SIZE is set to 1024, which means that it reads the data in chunks of 1024 frames
it will keep writing in 1024 chuncks until all numItems have been written (numItems/BUF_SIZE)
Needs to be on a while loop otherwise it will only write the first 1024 frames of the file
*/
while ((readCount = sf_read_double(infile, buffer, BUF_SIZE)))
{
watermark(buffer, readCount, info.channels);
sf_write_double(outfile, buffer, readCount);
};
for (i = 0; i < sizeof(buffer) / sizeof *buffer; i++)
{
printBuffer(buffer, sizeof(buffer)/sizeof *buffer);
}
/*
Can only close SF_open once both reading/writing has been done
if you close infile after the read, it's not able to copy the audio
data from infile to write into outfile
*/
sf_close(infile);
sf_close(outfile);
return;
}
void readFile(int fileNumber)
{
SF_INFO info;
SNDFILE *infile;
char *Files[] = { "File1Output.wav", "File2Output.wav", "File3Output.wav"
, "File4Output.wav", "File5Output.wav" };
char *inputFile = Files[fileNumber - 1];
infile = sf_open(inputFile, SFM_READ, &info);
printf("You have opened: %s\n", Files[fileNumber - 1]);
printInfo(info.frames, info.channels, info.samplerate);
sf_close(infile);
return;
}
int numItems(int frames, int channels)
{
int numItems = frames * channels;
return numItems;
}
void printInfo(int frames, int channels, int sampleRate)
{
printf("Number of Frames = %d\n", frames);
printf("Number of Channels = %d\n", channels);
printf("Sample Rate = %d\n", sampleRate);
}
void watermark(double *buffer, int count, int channels)
{
double value[MAX_CHANNEL] = { 0.0, 0.0 };
int i, j;
if (channels > 1)
{
/*
Sets j to be the first channel and while i is less than 1024/5, i += channels
buffer[3] value is multiplied by 0, and set to 0
this mutes that particular index value or frame
this keeps going until i>=1024/5 and then the next channel is chosen where j = 2
buffer[4] value is multiplied by 0 and set to 0
this keeps going until i>=1024/5 where it calls back to the while loop in processFile
*/
for (j = 0; j < channels; j++)
{
for (i = j; i < count / 5; i += channels)
{
buffer[i] *= value[j];
}
}
}
else
{
/*
If audio file has 1 channel, buffer[i] is set to 0 for all values < 1024/5 frames
and it goes back to normal until the next 1024 frames where the first 1024/5 frames.
*/
for (i = 0; i < count / 5; i++)
{
buffer[i] *= value[0];
}
}
return;
}
void printBuffer(double *buffer, size_t count)
{
int i;
for (i = 0; i < count; i++)
{
if (i != 0)
printf("%d\n", buffer[i]);
}
}
/*
- *DONE* - Need to create function that will read the newly outputted file
- Find where the watermarks have been left on the audio
- Compare buffer[] values between original file and new outputted file
*/
while ((readCount = sf_read_double(infile, buffer, BUF_SIZE)))
{
watermark(buffer, readCount, info.channels);
sf_write_double(outfile, buffer, readCount);
};
Here, you use the buffer again and again to read some data, watermark it and write it out.Only once you are done, you print the last remaining data out of the buffer:
for (i = 0; i < sizeof(buffer) / sizeof *buffer; i++)
{
printBuffer(buffer, sizeof(buffer)/sizeof *buffer);
}
So, with
#define MAX_CHANNEL 2
#define BUF_SIZE 1024
and a wave file with 16 bit 44100 stereo, you will only see the last 5.8ms of sound data, which probably is almost silence, if you have normal audio like music or some high quality recorded voice with almost no noise.
Additionally: Depending on the last block read, you see the tail of the file, and then some part prior to the tail, like you see the last 3.2ms and then the 2.6ms prior to that, which was not overwritten in the last read call.
/edit: Ok, probably I got the numbers wrong, data type is double and so on, but the conceptual error is the same.
/edit 2: Looking at Jonathan Leffler's comment, I see there are even more errors ... - I recommend switching on ALL compiler warnings, and try to understand (and fix) them.
/*Project 1
Student records
1. Read the file with the records
2. store them
3. sort them
4. output them
ex. input and output (SORTED by student ID
2040003 AAAA BBBBBBBBB ComputerScience 3.45
2040002 AAA CCC ElectricalEngineering 3.01
2040005 AAAAAAAAAAAAAAAAA BBB ComputerScience 3.60
2040002,AAA,CCC,ElectricalEngineering,3.01
2040003,AAAA,BBBBBBBBB,ComputerScience,3.45
2040005,AAAAAAAAAAAAAAAAA,BBB,ComputerScience,3.60
char* name = malloc(256*sizeof(char));
*/
int main()
{
typedef struct StudentRecords
{
int StudentID; //must be of size 7 between 1000000 and 9999999
char *Firstname; //= MALLOC(256*sizeof(char)); // must be any length and allocate memory dynamically.
char *Lastname; //= MALLOC(256*sizeof(char));
char *Department; //= MALLOC(256*sizeof(char));
float GPA; // must be between 0 and 4
} STUDENTRECORDS;
/*
First job is read the file
*/
//set variables
int i=0;
char filecontent, file_name[100];
FILE *fp;
STUDENTRECORDS StudentRecords[300];
STUDENTRECORDS a[300];
int size =0;
printf("Enter directory of file\n"); // instructs user to enter directory of file
gets(file_name); //prompt use
fp = fopen(file_name,"r"); //opens the file "r" is read mode for fopen()
// here is a check to see if fp is empty and throw an error if so
if (fp == NULL)
{
perror("Could not open file\n");
exit(EXIT_FAILURE);
}
printf("The contents of %s file are :\n", file_name); // just prints the file name (file_name) you are prompted for
// here is where the printing of contents actually occurs
while ((filecontent = fgetc(fp)) != EOF) // I think EOF is end of feed here, not 100%
{
printf("%c",filecontent);
}
//I thought this line was to figure out how many lines are in the text, but it isnt working.
while (!feof(fp))
{
read(StudentRecords, i, fp);
i++;
}
//because the while statement isnt working, Ive elected to setting size to 3 in order to continue coding.
size = i = 3;
printf("Size = %d\n", size);
//I thought this essentially put the files contents into
for (i = 0; i < size; ++i)
fscanf(fp, "%d %s %s %s %f\n", &StudentRecords[i].StudentID, &StudentRecords[i].Firstname, &StudentRecords[i].Lastname, &StudentRecords[i].Department, &StudentRecords[i].GPA);
for (i = 0; i < size; ++i)
printf("%s", StudentRecords[i]);
//printf("%d %s %s %s %f/n", &StudentRecords[i].StudentID, &StudentRecords[i].Firstname, &StudentRecords[i].Lastname, &StudentRecords[i].Department, &StudentRecords[i].GPA);
for (i = 0; i < size; ++i)
fscanf(fp, "%d %s %s %s %f\n", &a[i].StudentID, &a[i].Firstname, &a[i].Lastname, &a[i].Department, &a[i].GPA);
for (i = 0; i < size; ++i)
printf("%s", a[i]);
//printf("%d %s %s %s %f/n", &a[i].StudentID, &a[i].Firstname, &a[i].Lastname, &a[i].Department, &a[i].GPA);
// fclose() must follow an fopen()
fclose(fp);
//printf("%g", &StudentRecords);
// return code
return 0;
}
How do I add information into a struct and print it or use it? This is what
i have so far. I've tried many different things and to no avail. I think the problem is with my initializing my struct for use. I can't get it right. I've tried searching for a solution, but each one is different and don't explain much.
Thanks for any suggestions.
Please find example code for reading content from file and storing it in structure also for this example have only take 5 student data entry(you can change as you wish) And on which criteria you want to do sorting? So i leave sorting on you.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ENTRY 5
typedef struct StudentRecords
{
int StudentID; //must be of size 7 between 1000000 and 9999999
char *Firstname; //= MALLOC(256*sizeof(char)); // must be any length and allocate memory dynamically.
char *Lastname; //= MALLOC(256*sizeof(char));
char *Department; //= MALLOC(256*sizeof(char));
float GPA; // must be between 0 and 4
} STUDENTRECORDS;
int main()
{
/*
First job is read the file
*/
//set variables
int i=0;
char filecontent, file_name[100];
FILE *fp;
STUDENTRECORDS StudentRecords[MAX_ENTRY];
for(i=0;i<MAX_ENTRY;i++)
{
StudentRecords[i].Firstname = malloc(sizeof(char)*256);
StudentRecords[i].Lastname = malloc(sizeof(char)*256);
StudentRecords[i].Department = malloc(sizeof(char)*256);
}
printf("Enter directory of file\n"); // instructs user to enter directory of file
gets(file_name); //prompt use
fp = fopen(file_name,"r"); //opens the file "r" is read mode for fopen()
// here is a check to see if fp is empty and throw an error if so
if (fp == NULL)
{
perror("Could not open file\n");
//exit(EXIT_FAILURE);
}
i=0;
while(EOF!=fscanf(fp, "%d %s %s %s %f\n", &StudentRecords[i].StudentID, StudentRecords[i].Firstname, StudentRecords[i].Lastname, StudentRecords[i].Department, &StudentRecords[i].GPA))
{
printf("%d %s %s %s %f\n", StudentRecords[i].StudentID, StudentRecords[i].Firstname, StudentRecords[i].Lastname, StudentRecords[i].Department, StudentRecords[i].GPA);
i++;
}
// fclose() must follow an fopen()
fclose(fp);
return 0;
}
Note: never forgot to free string which allocated by malloc after it's use.
A few comments, and some suggestions:
Was it your lecturer who said to use a linked-list? If so.. you really should do that otherwise you'll lose marks for failing to meet the spec.
EOF is 'End Of File'. feof() tells you if the stream pointer passed to it has hit EOF already.
Your while loop to print the contents is inefficient. Rather than reading every. single. character. in. the. file., you should read the entire file (or at least, large chunks thereof, let's not assume infinite memory), fclose() the stream and then operate on the read-in file.
Also, this sort of exercise lends itself very well to fixed-size record
Omitting error handling, variable declarations, structures and
using some pseudocode:
stat("/path/to/file", &statbuf)
inputfd = fopen("/path/to/file", r);
/* assuming that we only have a small file... */
contents = calloc(statbuf.st_size * sizeof(char));
/* read it all in, in one big chunk */
fread(contents, statbuf.st_size, 1, inputfd);
fclose(inputfd);
/* Now you can operate on it however you like */
bytesleft = statbuf.st_size;
/*
* this might need to go at the top of your block, depends on if you
* have enabled C99
*/
char eachline[MAXLINELENGTH];
int n = 0;
while (bytesleft > 0) {
add_new_list_element(mylist);
bzero(eachline, MAXLINELENTH);
memccpy(&eachline, contents[n], '\n', MAXLINELENGTH);
bytesleft -= sizeof(eachline);
nread = sscanf(start, "USE YOUR FORMAT STRING HERE", [variable list]);
if (nread < 0)
/* handle EOF, remember to make use of errno */
}
call_my_sort_function(mylist);
for (; thiselement != NULL; thiselement = thiselement->next)
print_salient_field_values(thiselement);
This is for a beginner's C programming unit. I'm trying to read a text file containing MAC addresses and the data they received, separate out the relevant data (address and number of packets), copy the addresses to an array without repeating any of them and sum the associated number of packets if an identical address is encountered.
I can read the file in just fine, and get the bits of each line I want without issue, but when I try to check each address read against those already in the array I hit a problem. Depending on the location of the integer counting the number of full lines, the program either fails to recognise identical strings and prints them all as they are in the file, or prints them over one another in addresses[0], leaving me with only the last address. I'm stumped and need some fresh eyes on this - any suggestions would be greatly appreciated.
My code follows:
static void readadds(char filename[])
{
FILE* packetfile = fopen(filename, "r");
FILE* datafile = fopen("packdata.txt", "w+");
// Open file from input; create temporary file to store sorted data.
char line[100];
char addresses[500][18];
int datasize[500];
int addressno = 0;
// Create storage for lines read from text file, addresses and related data.
if(packetfile != NULL)
{
while(fgets(line, sizeof line, packetfile) != NULL)
{
int linenum = 0;
char thisadd[18];
int thisdata;
//Create arrays to temp store data from each line
sscanf(line, "%*s %*s %s %i", thisadd, &thisdata);
for(int i = 0; i < 500; i++)
{
if(strcmp(thisadd, addresses[i]) == 0)
{ //check if the address is already in the array
int x = datasize[i];
datasize[i] = x + thisdata; //sum packet data if address already exists
printf("Match!\n");
break;
}
else
{
strcpy(addresses[linenum], thisadd); //initialize new address
datasize[linenum] = thisdata; //initialize assoc. data
linenum++;
addressno++;
printf("Started!\n");
break;
}
}
}
for(int i = 0; i <= addressno; i++)
{
printf("%s %i\n", addresses[i], datasize[i]);
fprintf(datafile,"%s %i\n", addresses[i], datasize[i]);
}
}
fclose(packetfile);
fclose(datafile);
}
This version prints over addresses[0]. If linenum is replaced by addressno in the for() loop, identical strings are not recognised. My dataset is arranged like this:
1378251369.691375 84:1b:5e:a8:bf:7f 68:94:23:4b:e8:35 100
1378251374.195670 00:8e:f2:c0:13:cc 00:11:d9:20:aa:4e 397
1378251374.205047 00:8e:f2:c0:13:cc 00:11:d9:20:aa:4e 397
1378251374.551604 00:8e:f2:c0:13:cc 00:11:d9:20:aa:4e 157
1378251375.551618 84:1b:5e:a8:bf:7c cc:3a:61:df:4b:61 37
1378251375.552697 84:1b:5e:a8:bf:7c cc:3a:61:df:4b:61 37
1378251375.553957 84:1b:5e:a8:bf:7c cc:3a:61:df:4b:61 37
1378251375.555332 84:1b:5e:a8:bf:7c cc:3a:61:df:4b:61 37
I'm almost certain this is what you're trying to do. The logic to add a new entry was incorrect. You only add one if you have exhausted searching all the current ones, which means you need to finish the current for-search before the add.
Note: Not tested for compilation, but hopefully you get the idea.
static void readadds(char filename[])
{
// Open file from input; create temporary file to store sorted data.
FILE* packetfile = fopen(filename, "r");
FILE* datafile = fopen("packdata.txt", "w+");
// Create storage for lines read from text file, addresses and related data.
char addresses[500][18];
int datasize[500];
int addressno = 0;
if (packetfile != NULL)
{
char line[100];
while(fgets(line, sizeof line, packetfile) != NULL)
{
char thisadd[18];
int thisdata = 0;
//Create arrays to temp store data from each line
if (sscanf(line, "%*s %*s %s %i", thisadd, &thisdata) == 2)
{
// try to find matching address
for(int i = 0; i < addressno; i++)
{
if(strcmp(thisadd, addresses[i]) == 0)
{
//check if the address is already in the array
datasize[i] += thisdata;;
printf("Match!\n");
break;
}
}
// reaching addressno means no match. so add it.
if (i == addressno)
{
printf("Started!\n");
strcpy(addresses[addressno], thisadd); //initialize new address
datasize[addressno++] = thisdata; //initialize assoc. data
}
}
else
{ // failed to parse input parameters.
break;
}
}
for(int i = 0; i <= addressno; i++)
{
printf("%s %i\n", addresses[i], datasize[i]);
fprintf(datafile,"%s %i\n", addresses[i], datasize[i]);
}
}
fclose(packetfile);
fclose(datafile);
}
My program requires me to read a dat file with a list of numbers. My goal is to get each number and add them to an array. The file has around 100 numbers in this format:
1
2
3
(styling is a bit off sorry ;[ )
so far i have
int main()
{
double prices[1000];
int count,price;
FILE *file;
file = fopen("price.dat","r");
if(file == NULL)
{
printf("Error: can't open file to read\n");
}
else
{
printf("File prices.dat opened successfully to read\n");
}
if (file){
while (fscanf(file, "%d", &price)!= NULL){
count++;
prices[count]=price;
}
}
fclose(file);
}
Problem is that it continues adding the last number continuously. Any help?
You have several problems in your code. To name a few:
fscanf doesn't return a pointer so you shouldn't be comparing it with NULL. All scanf functions returns an integer which can be positive, zero or negative.
You don't initialize count so it will contain a seemingly random value.
Indexing of arrays starts a zero, so you should not increase the array index count until after the assignment.
The actual problem with not wanting to stop is because of the first point.
#include <stdio.h>
#include <string.h>
#define PRICES_LIST_MAX 1000
#define PRICES_FILE "price.dat"
int main()
{
double prices[PRICES_LIST_MAX];
int count = 0;
int i = 0;
FILE *file;
file = fopen(PRICES_FILE,"r");
if(!file)
{
perror("Error opening file");
return -1;
}
memset(prices, 0, sizeof(prices));
while (!feof(file) /* Check for the end of file*/
&&(count < PRICES_LIST_MAX)) /* To avoid memory corruption */
{
fscanf(file, "%lf", &(prices[count++]));
}
fclose(file);
/* Print the list */
printf("Prices count: %d\n", count);
for(i = 0; i < count; i++)
{
printf("Prices[%d] = %lf\n", i, prices[i]);
}
return 0;
}