problem while getting data from file and store in array

Discussion in 'C Programming' started by TroubleInLang, Nov 10, 2008.

  1. TroubleInLang

    TroubleInLang

    Joined:
    Nov 10, 2008
    Messages:
    1
    #include<stdio.h>
    #include<conio.h>
    #include<alloc.h>
    #include<stdlib.h>
    #include<process.h>
    #include<string.h>

    typedef struct node;
    struct node
    {
    char Nname[10],Nbrand[10],Ncity[10];
    int Nday[10],Nmonth[20],Nyear[10],Nsal[10];
    node *next;

    };

    void main()
    {
    FILE *fp;
    clrscr();
    fp = fopen ("Doc.txt","rb");
    node *head,*temp;
    temp =(node*) malloc(sizeof(node));
    char ch[100];
    static int nm=0,bd=0,yr=0,mnth=0,dy=0,sl=0,cty=0;
    char name[10],brand[10],city[10];
    int day[10],month[10],year[10],sal[10];
    if(fp == NULL)
    {
    printf("cant open");
    }
    else
    { int i =0,count = 0;


    while((ch=getc(fp))!= EOF)
    {

    if(ch=='\n'){
    count = 0;}
    switch(count)
    {
    case 0 : if(ch=='|')
    {
    count = 1;
    i++;
    break;
    }
    name[nm] = ch;
    i++;
    nm++;
    break;
    case 1 : if(ch=='|'){ count = 2;i++; break; }
    brand[bd] = ch;
    bd++;
    i++;
    break;
    case 2 : if(ch =='|'){ count=3;i++;break;}
    day[dy] = atoi(int(ch));
    printf("%c\n",ch);
    printf("%d",day[dy]);
    i++;
    dy++;

    break;
    case 3 : if(ch=='|'){count =4;i++; break;}
    month[mnth]=int(ch);
    i++;
    mnth++;
    break;
    case 4 : if(ch=='|'){count = 5;i++; break;}
    year[yr] =int((ch));
    i++;
    yr++;
    break;
    case 5 : if(ch == '|'){count = 6 ;i++; break;}
    city[cty] = ch;
    i++;
    cty++;
    break;
    case 6 : sal[sl]=int(ch);
    i++;
    sl++;
    break;
    default : exit(1);


    }

    }

    }

    }
    i got some problem while getting the interger value from file and store it in the array..help to get over this problem....thnx in advance
    TroubleInLang, Nov 10, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    636
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  2. rhitz1218@gmail.com

    Store an array to an integer array??

    rhitz1218@gmail.com, Dec 11, 2006, in forum: C Programming
    Replies:
    7
    Views:
    259
    Barry Schwarz
    Dec 12, 2006
  3. Sintek
    Replies:
    1
    Views:
    484
    Sintek
    May 3, 2009
  4. Colin Steadman

    How do I store an array of data between pages?

    Colin Steadman, May 13, 2004, in forum: ASP General
    Replies:
    11
    Views:
    210
    Roland Hall
    May 15, 2004
  5. George
    Replies:
    4
    Views:
    600
    Roedy Green
    Jun 28, 2012
Loading...

Share This Page