#include<conio.h>
#include<string.h>
//prototype declaration
int pnc1(FILE *fp);
int pnc2(FILE *fp);
int findstr(char *p[], char *name);
int sum_array(int a[][], int element);
//function to pick data and then convert bits to number
// for notes_disp , notes_req
int pnc1(FILE *fp)
{
int tot=i=j=k=0;
i=getw(fp);
j=getw(fp);
k=getw(fp);
tot=(100 * i) + (10 * j) + k;
return(tot);
}
//for notes_rejt
int pnc2(FILE *fp)
{
int tot=i=j=0;
i=getw(fp);
j=getw(fp);
tot=(10 * i) + j;
fseek(fp,1,SEEK_CUR);
return(tot);
}
//find a string and returns value
int findstr(char *p[], char *name)
{
int t;
for(t=0; p[t]; ++t) {
if(!strcmp(p[t],name))
return t;
}
return -1;// string not found
}
//calculates total of array elements i
int sum_array(int a[][], int element)
{
int j, sum=0;
for(j=0; j<=elements; j++) {
sum=sum+a[][j];
}
}
//main starts
void main()
{
FILE *fp;
int notes_disp[][], notes_req[][], notes_rejt[][];
int flag=1;
int i=0,m;
int sum, sum2,j;
int disp_sum[3], req_sum[3], rejt_sum[3];
char c,temp1,temp2;
char buffer[500];
fp=fopen("CashDispense_Log_18_10_2011.txt","r"); // open file
if (fp==NULL)
perror ("The following error occurred : "); // if file not open, print error
else {
do {
c=fgetc(fp); // takes a character
if(c=='%') {
if(flag==1) {
do {
temp1=fgetc(fp);
if(temp1=='A') {
sum=pnc1(fp);
notes_req[i][0]=sum;
}
if(temp1=='B') {
sum=pnc1(fp);
notes_req[i][1]=sum;
}
if(temp1=='C') {
sum=pnc1(fp);
notes_req[i][2]=sum;
}
if(temp1=='D') {
sum=pnc1(fp);
notes_req[i][3]=sum;
}
flag=0;
}
while(!fgetc(fp)==" ");
}
else { //flag==0
fseek(fp,4,SEEK_CUR);
do {
temp2=fgetc(fp);
if(temp2=='A') {
sum=pnc1(fp);
notes_disp[i][0]=sum;
sum2=pnc2(fp);
notes_rejt[i][0]=sum2;
}
if(temp2=='B') {
sum=pnc1(fp);
notes_disp[i][1]=sum;
sum2=pnc2(fp);
notes_rejt[i][1]=sum2;
}
if(temp2=='C') {
sum=pnc1(fp);
notes_disp[i][2]=sum;
sum2=pnc2(fp);
notes_rejt[i][2]=sum2;
}
if(temp2=='D') {
sum=pnc1(fp);
notes_disp[i][3]=sum;
sum2=pnc2(fp);
notes_rejt[i][3]=sum2;
}
flag=1;
}
while(!fgetc(fp)==" ");
}
i++;
}
}
while(!feof(fp));
//test dispenser count
fseek ( fp , 0L , SEEK_SET );// reset to beginning of file
//calculate total rejected till yet
for(r=0; r<=3; r++) {
rejt_sum[r]=sum_array(notes_rejt, i);
disp_sum[r]=sum_array(notes_disp, i);
req_sum[r]=sum_array(notes_req, i);
}
fseek(fp,0,SEEK_SET);
do {
fgets(buffer,500,fp);
if(findstr(buffer,"Type 1 Rejected")!=1) {
sscanf(buffer,"Type 1 Rejected %4d",&m);
if(m>rejt_sum[0])
rejt_sum[0]=rejt_sum[0]+(m-rejt_sum[0]);
else
rejt_sum[0]=rejt_sum[0]+m;
}
if(findstr(buffer,"Type 2 Rejected")!=1) {
sscanf(buffer,"Type 2 Rejected %4d",&m);
if(m>rejt_sum[1])
rejt_sum[1]=rejt_sum[1]+(m-rejt_sum[1]);
else
rejt_sum[1]=rejt_sum[1]+m;
}
if(findstr(buffer,"Type 3 Rejected")!=1) {
sscanf(buffer,"Type 3 Rejected %4d",&m);
if(m>rejt_sum[2])
rejt_sum[2]=rejt_sum[2]+(m-rejt_sum[2]);
else
rejt_sum[2]=rejt_sum[2]+m;
}
if(findstr(buffer,"Type 4 Rejected")!=1) {
sscanf(buffer,"Type 4 Rejected %4d",&m);
if(m>rejt_sum[3])
rejt_sum[3]=rejt_sum[3]+(m-rejt_sum[3]);
else
rejt_sum[3]=rejt_sum[3]+m;
}
}
while(!feof(fp));
//printing values
printf("\n\n Number of times Dispenser called : %d",i);
printf("\n\n Number of notes Requested\n \t TYPE_1 %d \t TYPE_2 %d \t TYPE_3 %d \t TYPE_4 %d",sum_req[0],sum_req[1],sum_req[2],sum_req[3]);
printf("\n\n Number of notes Dispensed\n \t TYPE_1 %d \t TYPE_2 %d \t TYPE_3 %d \t TYPE_4 %d",sum_disp[0],sum_disp[1]),sum_disp[2];
,sum_disp[3]
printf("\n\n Number of notes Rejected\n \t TYPE_1 %d \t TYPE_2 %d \t TYPE_3 %d \t TYPE_4 %d",sum_rejt[0],sum_rejt[1]),sum_rejt[2];
,sum_rejt[3]
}
fclose (fp);
}
Recommended Answers
Jump to PostIs there a question?
Jump to PostThere is no excuse not to say anything in a help forum. We are not robots: we don't communicate in code. If you are not comfortable with the English language, its okay. We will not criticise your speech. But you must explain yourself, otherwise you are just spamming the site.
Jump to PostMaybe these are just code snippets. :|
All 9 Replies
thines01
401
Postaholic
Team Colleague
Featured Poster
robinpurbia
-2
Newbie Poster
D33wakar
commented:
Thanks, that's very generous of you!
-1
N1GHTS
102
Posting Whiz in Training
thines01
401
Postaholic
Team Colleague
Featured Poster
N1GHTS
102
Posting Whiz in Training
robinpurbia
-2
Newbie Poster
N1GHTS
102
Posting Whiz in Training
robinpurbia
-2
Newbie Poster
zeroliken
79
Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.