   writing data to hd that Excel can read
  I'm trying to write data that i need to import into Excel, I'm storing the data in an array, like this:intPixel[2000];Then I fill the array with the amount of occurances that occur at a position,so if #0 is seen 5 times and say #3 is seen 18 times, the array would look like this:Pixel[0]=5;Pixel[3]=18;I'm now trying to output it in a format that I can paste into Excel, something like0 51 02 03 184 0...etcHow do I export the data so each integer comes out as a readable number in a text file, if I output it like shown below, each number is output as an ascii, for example if I want the number 5 I have to output ascii#53, if I want to output 18, I have to output ascii#49 followed by ascii#56... this is too much conversion I just want to spit out the data either as above or even like500180...etc/*-------------------------------------------------------------------------------*|||||||||||||||||||||||||||||||||||| SaveData  |||||||||||||||||||||||||||\*-------------------------------------------------------------------------------*/intSaveData(){charFileName[13];//, tString[5];FILE*stream;interr;//-------------------------------------------------------------strcpy_s(FileName,"Save.txt"); // Open for writing (will fail if file FileName can not be created)if( (err  = fopen_s( &stream, FileName, "wb" )) !=0 )MessageBox(NULL, "Could Not Save Info!", "Error Message", MB_OK);fwrite(Pixel,1,sizeof(Pixel),stream);fclose(stream);return TRUE;}// End SaveDataAny info would be appreciated... thanks,rhuala   
  Are you programming in C, or C++?Also, I imagine that you could probably just export the data in CSV format and then open it in Excel directly (no copying and pasting needed).   ;Quote:Original post by jykAre you programming in C, or C++?Also, I imagine that you could probably just export the data in CSV format and then open it in Excel directly (no copying and pasting needed).Oh sorry jyk, vc++2008... how do you export to CSV format?   ;  If you are using c++ then look up fstream. It's pretty simple to do what you want.If you want a CSV then just write your data that way. Write a number, then a comma, then a number, repeat as needed, add a newline, repeat as needed.fstream will convert your numbers to ascii format for you if you set it up for text file output.   ;Quote:how do you export to CSV format?Nothing special - just put a comma between each entry, and create the text file with the extension '.csv'. You can then load the file directly into Excel (it will put the array indices in one column, and the element counts in the next column).Since you're using C++, I'd suggest using C++'s stream classes. No guarantee of correctness, but the code to export the CSV file might look something like this:std::ofstream file("my_file.csv");if (!file) {    // Error handling goes here.}for (int i = 0; i < array_size; ++i) {    file << i << ", " << array << '\n';}// All done. The file will close itself when it goes out of scope,// but if you want to flush and close manually, you can write://file.close();;Quote:Original post by karwostsfstream will convert your numbers to ascii format for you if you set it up for text file output.Right, so how do I get it to not covert it to ascii, so that if I write "654", it will display "654" in the text file?right now this outputs "㔶4﻾﻾﻾" not "654", I'd like to see "654"charFileName[13];FILE*stream;fopen_s( &stream, FileName, "wb" )int t=654;_itoa_s(t,tString,10);fwrite(tString,1,sizeof(tString),stream);;Quote:Original post by rhualaQuote:Original post by karwostsfstream will convert your numbers to ascii format for you if you set it up for text file output.Right, so how do I get it to not covert it to ascii, so that if I write "654", it will display "654" in the text file?right now this outputs "㔶4﻾﻾﻾" not "654", I'd like to see "654"*** Source Snippet Removed ***I think he was referring to fstream as in std::fstream. In other words, what both karwosts and I are recommending is that you use C++ stream classes for this. (See my previous post for some example code.)   ;  Regarding your specific question, it's been a long time since I've done any file IO in C, but I think you probably want:strlen(tString)Rather than:sizeof(tString)The latter will just return 5 (the size of the array in bytes), which is probably why you're seeing 5 characters in your output.As for why the first three characters aren't correct, I'm not sure off the top of my head. What does the debugger show after the call to _itoa_s()?   ;Quote:Original post by rhualaQuote:Original post by karwostsfstream will convert your numbers to ascii format for you if you set it up for text file output.Right, so how do I get it to not covert it to ascii, so that if I write "654", it will display "654" in the text file?right now this outputs "㔶4﻾﻾﻾" not "654", I'd like to see "654"*** Source Snippet Removed ***You are opening your file in binary mode. Open it with "w" instead of "wb".   ;Quote:You are opening your file in binary mode. Open it with "w" instead of "wb".How would that account for the behavior the OP is seeing? (I agree that the file should probably be opened in text mode, but I'm not sure that using binary mode is the source of the problem here. I could be wrong though.)I tried the OP's code (using binary mode), and didn't have any problems. However, I tried it using GCC, using different functions (e.g. sprintf(), etc.), so the code was not exactly equivalent. Anyway, I'd again suggest using the debugger to see what the array holds after the call to _itoa_s().   