Thread: csv format

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    csv format

    Yesterday, 10:47 PM
    hello, Iam working on an application, which needs to extract data from excel sheet. I don't know COM programming.So i converted the excel sheet to CSV format.I am facing 2 particular problems .
    _________________________________
    Edfghj_89jkcf.h, , common\module

    _________________________________

    a file of the above format is in the first column , the second column is empty, and the third column contains the path.
    when i output it on the screen,
    i get something like this
    Edfghj_89jkcf.ha`
    , , common\module.
    in the file ext. notice the a`char after .h, it shouldn't be there.

    the second problem is , if the content in the cell is a sentence, then the each word of the sentence is being o/p on a new line.

    Code:
    #include<stdio.h>
    #include<string.h>
    
    int main(int argc, char *argv[])
    {
     int i,marker,k=0,pre=0,m,z;
     char store[200],file[70],path[150],prev_path[150],modpath[150];
     char add[150],refpath[150];
     FILE *j,*fp;
     
     j=fopen(argv[1],"r");//argv[1] specifies path of.csv file
     fscanf(j,"%s",store);//store record in array store
     for( i=0;i<200;i++)
      if(store[i]==',')  //find first ,
       marker=i-1;
     for(i=0;i<marker;i++)
     {file[i]=store[i];}
     file[i]='\0';
     for(i=(marker+2);store[i]!='\0';i++) //initialise file and path from store
      path[k++]=store[i];
     path[k]='\0';
     
     
     
        strcpy(prev_path,path);          //initialise prev_path
        strcpy(modpath,path);            //intialise modpath
     
     strcpy(add,argv[2]);      //argv[2] specifies destination dir of reference files
     for(z=0;z<150;z++)
     {
      if(modpath[z]==':')
       modpath[z]='#';
      else if (modpath[z]=='\\')
       modpath[z]='#';
     }
     strcat(add,"\\");
     strcat(add,modpath);
     strcat(add,".txt");
     strcpy(refpath,argv[3]);
     strcat(refpath,"\\");//argv[3] contains path of installation base dir.
     strcat(refpath,path);
      
        fp=fopen(add,"a+");
     fprintf(fp,"%s\n",refpath);
     fprintf(fp,"%s\n",file);
    while(!(feof(j)))                  //iterate for the remaining no. of records.
    {
     fscanf(j,"%s",store);
     if(!(feof(j)))
     {for( i=0;i<200;i++)
      if(store[i]==',')                    //get position of ','
       marker=i-1;
     for(i=0;i<marker;i++)
     {file[i]=store[i];}
     file[i]='\0';                            //intialise file and path from store  
     k=0;
     for(i=(marker+2);store[i]!='\0';i++)
      path[k++]=store[i];
     path[k]='\0';
     
     strcpy(modpath,path);                  //intialise modpath
     
            if(!(strcmp(path,"\0")))
     {  }
     else if(!(strcmp(path,prev_path)))
     {fprintf(fp,"%s\n",file);}
     else if(strcmp(path,prev_path))
     {
      fclose(fp);
      strcpy(add,argv[2]);    //argv[2] specifies destination dir of reference files
          for(z=0;z<150;z++)
     {
      if(modpath[z]==':')
       modpath[z]='#';
      else if (modpath[z]=='\\')
       modpath[z]='#';
     }
     strcat(add,"\\"); 
     strcat(add,modpath);
     strcat(add,".txt");
     
     strcpy(refpath,argv[3]);
     strcat(refpath,"\\");     //argv[3] contains path of installation base dir.
     strcat(refpath,path);
      
     fp=fopen(add,"a+");
     fprintf(fp,"%s\n",refpath);
     fprintf(fp,"%s\n",file);
     
     }
       
      strcpy(prev_path,path);
     }
    }
     
    }
    Please help me, this is urgent.Thanks in advance

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    A board search might turn up a useful thread.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  2. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 06:25 AM
  3. A Better Format Simulator
    By toonlover in forum C++ Programming
    Replies: 2
    Last Post: 01-07-2006, 06:14 PM
  4. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 05:41 AM
  5. problems with csv format
    By vacum in forum Tech Board
    Replies: 2
    Last Post: 06-20-2005, 09:21 PM