By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,382 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,382 IT Pros & Developers. It's quick & easy.

How export data from Visual C++ to CSV?

P: 14
Hi!

Can someone explain me the steps to follow to export the data originated in a dialog based visual c++ (version 6.0) program to a CSV file?

I've tried somthing like this:
Expand|Select|Wrap|Line Numbers
  1. void CSizeDistributionDlg::OnSave() 
  2. {
  3.     // TODO: Code für die Behandlungsroutine der Steuerelement-Benachrichtigung hier einfügen
  4.     const char *filename = "C:\Documents and Settings\X\Desktop\trycsv.csv";
  5.    FILE *Archi;
  6.    Archi = fopen(filename,"w");
  7.    if (Archi==0)
  8.       fprintf(stderr, "Fallo abriendo... %s para escribir\n",filename);      
  9.    fprintf(Archi,"Hola mundo\n");
  10.    fprintf(Archi,"Hola,Mundo\n");//etc...
  11.    fclose(Archi); 
  12. }
  13.  
  14. void CSizeDistributionDlg::OnOpen() 
  15. {
  16.     // TODO: Code für die Behandlungsroutine der Steuerelement-Benachrichtigung hier einfügen
  17.     char linea[100], cadena[100];
  18.    const char *filename = "C:\Documents and Settings\X\Desktop\trycsv.csv";
  19.    FILE *Archi;
  20.    Archi = fopen(filename,"r");
  21.    if (Archi==0)
  22.       fprintf(stderr,"Fallo al abrir %s \n",filename);
  23.  
  24.    for(int j=0;;j++){//total lineas
  25.       if (feof(Archi)) break;
  26.       for (int i=0;i<100;i++) {//caracteres          
  27.          linea[i]=fgetc(Archi);
  28.          if (linea[i]=='\n') break;
  29.          if (feof(Archi)) break;
  30.       }
  31.       linea[i] = '\n';   //fin d datos de las celdas   
  32.       strcpy(cadena, linea); //ultima cadena
  33.    }   
  34.    fclose(Archi);    
  35. }
  36.  
  37.  

but it gives me errors when running it (Debug assertion failed)

Should I include something else, like headers or classes...?? I'm quite new in programming and I have not a global vision of this....

The reason I need to export to CSV is to open then with excel...

Thank you in advance!!
May 25 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Yes, there are requirements for a .csv file in terms of headers and formatting.

You should search MSDN for this.

Just having a .csv in the file name is not enough.
May 25 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.