The Student Room Group

C Programming Issue - URGENT - Please help

Hi Everyone,

I am currently working on a C computing project and have managed to export stored data to excel as a table. However I am hoping to improve this and:

1.) Get excel to open automatically to display the table without me opening the file from my documents
2.) And also plot a graph of the data stored in excel using c coding

My code currently reads:

FILE * fp;

fp = fopen ("tableoftpgk.csv", "w+");
fprintf(fp, "Time (s),Momentum(Kg m/s),GPE(MJ),KE(MJ)\n");
for (i=0;i<(end/dt);i++){
fprintf(fp, "%f,%f,%f,%f\n",stored_t,stored_Momentum,stored_Epotential,stored_Ekinetic);
}
fclose(fp);

As you can see I am using formulas to calculate Momentum, Potential Energy and Kinetic Energy as Time, T goes by.

Is it possible to get Excel to open automatically and can I get this data to be plotted in Excel?

Any help would be MASSIVELY appreciated and I will give positive feedback for any help.

PS: My compiler is Dev-C
Original post by Futureengineer1
Hi Everyone,

I am currently working on a C computing project and have managed to export stored data to excel as a table. However I am hoping to improve this and:

1.) Get excel to open automatically to display the table without me opening the file from my documents
2.) And also plot a graph of the data stored in excel using c coding

My code currently reads:

FILE * fp;

fp = fopen ("tableoftpgk.csv", "w+");
fprintf(fp, "Time (s),Momentum(Kg m/s),GPE(MJ),KE(MJ)\n");
for (i=0;i<(end/dt);i++){
fprintf(fp, "%f,%f,%f,%f\n",stored_t,stored_Momentum,stored_Epotential,stored_Ekinetic);
}
fclose(fp);

As you can see I am using formulas to calculate Momentum, Potential Energy and Kinetic Energy as Time, T goes by.

Is it possible to get Excel to open automatically and can I get this data to be plotted in Excel?

Any help would be MASSIVELY appreciated and I will give positive feedback for any help.

PS: My compiler is Dev-C


Good luck is all I can say... you'd be better off using python to plot something using the pyplot library. Excel and C are very hard to intergrate at all let alone integrate well and it sounds like you are relatively new to coding so you'll really struggle...
Have you / are you able to consider(ed) using C++/CLI or C# for this? TMN, both can hook into office pretty well but you'd want to check since I haven't tried it myself so can't advise if it's appropriate for this situation.
Original post by natninja
Good luck is all I can say... you'd be better off using python to plot something using the pyplot library. Excel and C are very hard to intergrate at all let alone integrate well and it sounds like you are relatively new to coding so you'll really struggle...


Thanks. See my credentials below.

Futureengineer1
20 Year Old PHD Student in Computer Science
Kings College - Cambridge
Original post by anunoriginaluser
Have you / are you able to consider(ed) using C++/CLI or C# for this? TMN, both can hook into office pretty well but you'd want to check since I haven't tried it myself so can't advise if it's appropriate for this situation.


I'm afraid not - The assignment is to be completed in C only. Is what I ask possible to do or is it worth scrapping the ideas?
Original post by Futureengineer1
I'm afraid not - The assignment is to be completed in C only. Is what I ask possible to do or is it worth scrapping the ideas?

It's probably possible but I'd doubt Microsoft would bother making a C API for office manipulation when there's already a good .NET API and C is barely used for these kinds of projects any-more, so it'll probably be stupidly difficult and probably even involve a lot of mucking about with office source

Realistically, I'd doubt it'd be viable, unfortunately. :frown:


//
Just looked it up and from a glance it looks like you can hook them up to C DLLs, but it sounds like it'd be a lot of effort to get working.

Edit


I just re-read what you wanted to do; opening Excel is probably easily done (See http://www.dreamincode.net/forums/topic/18057-run-external-executable/)

The graph might not be too awful either; I'd first see if xlsx format is easily readable/writeable for a couple cells and a chart (I wouldn't bet on it).

Would it be too abstracted/sneaky to use a macro? :P
(edited 9 years ago)
Original post by Futureengineer1
Thanks. See my credentials below.

Futureengineer1
20 Year Old PHD Student in Computer Science
Kings College - Cambridge


See my credentials below:

20 Year Old master's student in Physics, Queen's College Oxford
Patented data compression algorithm
8 months industry experience writing C firmware

I advise you to give up. Excel's API is horrible. I advise you not to try to write a program to plot in excel. Would be easier to use a C gui library...

Also, if you are any good at writing C there should be no compiler dependent behaviour...
(edited 9 years ago)

Quick Reply

Latest

Trending

Trending