-
January 23rd, 2013, 06:38 PM
#1
Writing Structure to CSV file - won't work... HELP!
I need to compute some values, place them in a structure containing two vector variables, and save them in a CSV file. Right now, I can't even generate a file. I wrote the structure definition and file writing code in a header file (after first borrowing it). I have a "button" that is supposed to trigger all of the activity. I'll attach the code below:
HEADER
________-----_______------
#ifndef EINSTEIN_H
#define EINSTEIN_H
#include <stdio.h>
struct SizeAll{
int year;
double R;
};
int write_to_file(int count, struct SizeAll *data, char const *fileName)
{
FILE *f = fopen(fileName, "w");
if (f == NULL) return -1;
while (count-- > 0) {
// you might want to check for out-of-disk-space here, too
fprintf(f, "%d,%d", data->year, data->R);
++data;
}
fclose(f);
return 0;
}
#endif
BUTTON CODE
_____-------______-------
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
double R;
int counter,year,retval;
struct SizeAll Universe;
char const NameFile[62]="D:\\Documents and Settings\\Jumbo\\Desktop\\Friedout.csv";
Universe.R = 1;
Universe.year = 2;
for ( counter = 1 ; counter < 2 ; counter++ )
R = R + 1;
if (counter ==1)
retval=write_to_file(1, &Universe, NameFile);
}
};
}
Can anyone help me to get this to work? My grasp of pointers and how and when to use them evaporated long ago.
Thank you!
Last edited by Protocol; January 31st, 2013 at 11:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|