The format of each line is: date\ttime\tstore name\titem description\tcost\tmethod of payment We want elements 2 (store name) and 4 (cost) We need to write them out to standard output, separated by a tab
I am looking to get the total sales per store. I checked by manually entering the data, but it doesn't seem to work on MapReduce. I am looking to find out the issue and its solution,Advice if possible to avoid such problems again bcause I am learning all this by myself from Udacity tutorials.
MAPPER
#include<stdio.h>
main()
{
size_t p;
int i,j,k;
char *A,*a;
char *store,*cost;
while(getline(&A,&p,stdin) != -1)
{
i=0,j=0,k=0;
for(a=A;*a!='\n'&& i<=5;a++)
{
if(*a=='\t')
{
i++;
if(i==2)
store=a+1;
if(i==4)
cost=a+1;
*a='\0';
}
}
if(i==5)
printf("%s\t%s",store,cost);
}
}
REDUCER
#include<stdio.h>
#include<string.h>
main()
{
size_t p;
int i,j,k,flag=0;
char *A,*a;
char storenow[100]={0},*sval,storepre[100]={0};
double val,valpre;
while(getline(&A,&p,stdin) != -1)
{
strcpy(storepre,storenow);
valpre=val;
a=A;
while(*A!='\t')
A++;
*A='\0';
A++;
sval=A;
sscanf(sval,"%lf",&val);
strcpy(storenow,a);
if(!(strcmp(storenow,storepre))||!flag)
val=val+valpre;
else
printf("%s\t%lf\n",storepre,valpre);
flag=1;
}
printf("%s\t%lf\n",storenow,val);
}