Read a .csv file in Windows 2000 using c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samuelpaulc
    New Member
    • Feb 2007
    • 8

    Read a .csv file in Windows 2000 using c

    I need to extract data from .csv file Using C/C++ and need to sort them out....
    Any help will be appreciated ...
    Thanks in advance....
  • rajesh6695
    New Member
    • Oct 2006
    • 96

    #2
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>

    int main()
    {
    FILE *fp;
    char buf[1];
    char a[20];
    char b[15];

    clrscr();

    printf("Enter the path of the file :");
    scanf("%s",&a);

    fp=fopen(a,"a+" );
    if(fp==NULL)
    {
    printf("Error : Not able to Open the file....\n");
    getch();
    exit(1);
    }

    printf("Content of a file ....\n");
    fseek(fp,0, SEEK_SET);
    while( !feof(fp) )
    {
    fread(buf, 1, 1, fp);
    if(buf[0]==',')
    {
    printf("\t");
    }
    else
    {
    printf("%c", (buf[0]));
    }
    }
    fclose(fp);
    printf("\nPress any key to leave the process...\n");
    getch();
    return 0;
    }


    Look out the code and also there is an one error u find that error and fix it.....

    Comment

    • samuelpaulc
      New Member
      • Feb 2007
      • 8

      #3
      Originally posted by rajesh6695
      #include <stdio.h>
      #include <conio.h>
      #include <string.h>
      #include <stdlib.h>

      int main()
      {
      FILE *fp;
      char buf[1];
      char a[20];
      char b[15];

      clrscr();

      printf("Enter the path of the file :");
      scanf("%s",&a);

      fp=fopen(a,"a+" );
      if(fp==NULL)
      {
      printf("Error : Not able to Open the file....\n");
      getch();
      exit(1);
      }

      printf("Content of a file ....\n");
      fseek(fp,0, SEEK_SET);
      while( !feof(fp) )
      {
      fread(buf, 1, 1, fp);
      if(buf[0]==',')
      {
      printf("\t");
      }
      else
      {
      printf("%c", (buf[0]));
      }
      }
      fclose(fp);
      printf("\nPress any key to leave the process...\n");
      getch();
      return 0;
      }


      Look out the code and also there is an one error u find that error and fix it.....
      Thanks a lot Rajesh...
      really appreciate it...

      Comment

      • samuelpaulc
        New Member
        • Feb 2007
        • 8

        #4
        Originally posted by samuelpaulc
        Thanks a lot Rajesh...
        really appreciate it...
        Rajesh fread is reading only 1 byte.....
        PLease give some info on std::fstream

        Comment

        Working...