problem while getting data from file and store in array

Joined
Nov 10, 2008
Messages
1
Reaction score
0
#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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top