writing double quote & comma delimited files

This is a discussion on writing double quote & comma delimited files within the C++ Programming forums, part of the General Programming Boards category; Hi, I am trying to write comma delimited info to text file with each item enclosed in double quotes similar ...

  1. #1
    emt
    emt is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    2

    Thumbs down writing double quote & comma delimited files

    Hi,

    I am trying to write comma delimited info to text file with each item enclosed in double quotes similar to vb write command.
    Any ideas on how to do it?

    File should look like:
    "112234.223","bob","123","23.2234","fred"

    Thanks

    code excerpt is:
    Code:
    #pragma hdrstop
    #include <condefs.h>
    
    
    //---------------------------------------------------------------------------
    #pragma argsused
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <io.h>
    #include <fcntl.h>
    #include <string.h>
    #include <sys\stat.h>
    #include <iostream.h>
    #include <fstream.h>
    
    
    
    USERES("Project2.res");
    //---------------------------------------------------------------------------
    int i,k;
     char fred;
     int numpts,crap1,crap2,crap3,maxpts;
     int ptno;
     float east,north,rl;
     char ch;
     int ipn[10000];
     float ipx[10000],ipy[10000],ipz[10000];
     int maxelements;
     int a,b,c,d;
     float t1x,t1y,t1z,t2x,t2y,t2z,t3x,t3y,t3z;
     int tri[10000];
     float x1[10000], y1[10000], x2[10000], y2[10000];
      float Z1[10000];
       float Z2[10000];
     float  x3[10000], y3[10000], Z3[10000];
     float cstep;
     int HowMany;
    float rl_diff1,length_line1;
    float delta_x1,delta_y1,low1,high1;
    int nstep;
    float level_diff11,level_diff12,Increment11,Increment12;
    int up,xd,yd;
    float xs,ys;
    float rl_diff2,length_line2;
    float level_diff22,level_diff23,Increment22,Increment23;
    float rl_diff3,length_line3;
    float level_diff31,level_diff33,Increment31,Increment33;
    float low2,high2,low3,high3;
    float delta_x2,delta_y2;
    float delta_x3,delta_y3;
    float low_loop;
    float j;
    int     no_of_goes;
    float crash;
    int tricon[20000];
    float con[20000];
    float conx[20000], cony[20000];
    int CON_NUM;
    int m;
    int y;
    char craptri[4];
    char crapline[5];
    char craprl[3];
    char buff[80];
    
    
    int main()
    {
     FILE *fp_in,*fp_out;
    
        char fn_in[12];
    fp_in=fopen("mik_arboe.1.node","r");
        if ( fp_in == NULL ) {
    	 printf("No Input File Found !!%s\n",fn_in);
    	 exit(1);
        }
        fscanf(fp_in,"%d%d%d%d",&numpts,&crap1,&crap2,&crap3);
    while  (!feof(fp_in)) {
    i=i+1;
            fscanf(fp_in,"%d%f%f%f%d%d",&ipn[i],&ipx[i],&ipy[i],&ipz[i],&crap1,&crap2);
    
    if (i==numpts) {
    break;
    }
            }
        printf("done something\n");
       // scanf("finished",ch);
      fclose(fp_in);
    maxpts = i;
    fp_out=fopen("triangles_c","w");
        fp_in=fopen("mik_arboe.1.ele","r");
        fscanf(fp_in,"%d%d%d",&maxelements,&crap1,&crap2);
    j=0;
    while  (!feof(fp_in)) {
          j=j+1;
          fscanf(fp_in,"%d%d%d%d",&a,&b,&c,&d);
        for (i=1;i<maxpts+1;i++) {
            if (b==ipn[i]) {
                t1x = ipx[i];
                t1y = ipy[i];
                t1z = ipz[i];
            }
            if (c==ipn[i]) {
                t2x = ipx[i];
                t2y = ipy[i];
                t2z = ipz[i];
            }
            if (d==ipn[i]) {
                t3x = ipx[i];
                t3y = ipy[i];
                t3z = ipz[i];
            }
        }
        fprintf(fp_out,"%3d %3f %3f %3f %3f %3f %3f\n",a, t1x, t1y, t1z, t2x, t2y, t2z);
        fprintf(fp_out,"%3d %3f %3f %3f %3f %3f %3f\n",a, t2x, t2y, t2z, t3x, t3y, t3z);
        fprintf(fp_out,"%3d %3f %3f %3f %3f %3f %3f\n",a, t1x, t1y, t1z, t3x, t3y, t3z);
    if (j==maxelements) {
    break;
    }
    }
    fclose(fp_out);
    typical file output is:

    1 255741.890625 271491.281250 347.925995 255749.171875 271488.500000 346.959991
    1 255749.171875 271488.500000 346.959991 255745.734375 271495.187500 348.208008
    1 255741.890625 271491.281250 347.925995 255745.734375 271495.187500 348.208008
    2 255749.171875 271488.500000 346.959991 255741.890625 271491.281250 347.925995
    Last edited by emt; 06-29-2003 at 06:33 PM.

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Show us what you have done so far, first.

    Edit: Thanks.
    Last edited by XSquared; 06-30-2003 at 12:20 AM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Err... please read this one, and then edit your first post. Thanks.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    To use double quotes inside of a string:
    eg:
    printf("This is a double quote: \" ");

    Research fprintf for more info on how to mix strings and numbers.


    Shouldn't this be in the C forum?

  5. #5
    emt
    emt is offline
    Registered User
    Join Date
    Jun 2003
    Posts
    2
    Thanks people the \" works great!

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Great merciful crap! So many global variables! Ewwwwww...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <io.h>
    #include <fcntl.h>
    #include <string.h>
    #include <sys\stat.h>
    #include <iostream.h>
    #include <fstream.h>
    Tsk tsk tsk... old-style #includes. Should be:
    Code:
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <io.h>
    #include <fcntl.h>
    #include <cstring>
    #include <sys\stat.h>
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. writing and reading files
    By oldie in forum C Programming
    Replies: 1
    Last Post: 07-03-2008, 04:54 PM
  3. Conversion From C++ To C
    By dicon in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 02:54 PM
  4. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21