0

Can someone please tell me how to send data from my program to excel. I have a loop which is iteratively printing values to the console:

printf("16 Bit:\n\n");
  for (n=0;n<numberOfValues;n++){
    printf("%.4x\n",rand16());
  }

but i need to send them to excel for analysis!! Please help

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by oggiemc
1

change printf to fprintf and write to a .csv file

FILE * fp = fopen("mydata.csv", "w");  // opens file to write ("w"), using the FILE pointer "fp"

//...

printf("16 Bit:\n\n");
  for (n=0;n<numberOfValues;n++){
    fprintf(fp, "%.4x\n", rand16());   // prints to the file, using the file pointer "fp"

//...

fclose(fp);  // close the file after you're done

}

Edited by jephthah: n/a

Votes + Comments
straight to the point once again, very helpful poster
1

glad it helped.

side note, you can write any kind of file you want, the question is will application "X" understand it.

.CSV file just means "comma separated values" and this extension is typically opened by Excel on default. ally comma-separated values (strings or numbers) will appear across the columns, newlines will move down to the next row.

A true Excel file is an .XLS file and you can not very easily write a valid .XLS file without going through a lot of contortions with the Windows API and OLE Automation.

you could have also easily written a .TXT file and just opened it in any basic text editor such as WordPad or TextPad.


.

Edited by jephthah: n/a

0

glad it helped.

side note, you can write any kind of file you want, the question is will application "X" understand it.

.CSV file just means "comma separated values" and this extension is typically opened by Excel on default. ally comma-separated values (strings or numbers) will appear across the columns, newlines will move down to the next row.

A true Excel file is an .XLS file and you can not very easily write a valid .XLS file without going through a lot of contortions with the Windows API and OLE Automation.

you could have also easily written a .TXT file and just opened it in any basic text editor such as WordPad or TextPad.


.

Thanks for the additional info..Will take note of that!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.