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

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 6 Years Ago by jephthah: n/a

Comments
straight to the point once again, very helpful poster

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 6 Years Ago by jephthah: n/a

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.