Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > problem while getting data from file and store in array

Reply
Thread Tools

problem while getting data from file and store in array

 
 
TroubleInLang TroubleInLang is offline
Junior Member
Join Date: Nov 2008
Posts: 1
 
      11-10-2008
#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[i]=getc(fp))!= EOF)
{

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

break;
case 3 : if(ch[i]=='|'){count =4;i++; break;}
month[mnth]=int(ch[i]);
i++;
mnth++;
break;
case 4 : if(ch[i]=='|'){count = 5;i++; break;}
year[yr] =int((ch[i]));
i++;
yr++;
break;
case 5 : if(ch[i] == '|'){count = 6 ;i++; break;}
city[cty] = ch[i];
i++;
cty++;
break;
case 6 : sal[sl]=int(ch[i]);
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting error while getting Google plus posts George Java 4 06-28-2012 07:53 PM
Read a file and store bits into an array Sintek Java 1 05-03-2009 05:14 AM
Store an array to an integer array?? rhitz1218@gmail.com C Programming 7 12-12-2006 12:43 AM
How to avoid getting BGP routes while getting a router's routing table ncosta@net.ipl.pt Cisco 2 01-25-2006 11:50 AM
to store or not to store an image =?Utf-8?B?UnVkeQ==?= ASP .Net 6 03-30-2005 05:51 AM



Advertisments