SlideShare a Scribd company logo
#include
#include
#include
#include
/*Structure for storing words received from each thread*/
struct return_val{
char wordlist[100][100];
int count[100];
} *arr;
pthread_t *threads;
int lines;
/*Aggregates Frequency Sum of different threads*/
int aggregate(char *a)
{
int sum = 0;
int i=0;
while(1)
{
if(i==lines) break;
int count = 0;
while(1)
{
if(arr[i].count[count] == -1)
{
break;
}
if(strcmp(a,arr[i].wordlist[count]) == 0)
{
sum += arr[i].count[count];
arr[i].count[count] = 0;
}
count++;
}
i++;
}
return sum;
}
/*Function executed by each thread on separate line*/
void *word_count(void* num)
{
int *ln = num;
unsigned int line_number = *ln;
line_number++;
char cmd_p1[9] = "sed -n '0";
char cmd_p2[2];
sprintf(cmd_p2,"%d",line_number);
char cmd_p3[14] = "p' 'file.txt'0";
char command[100];
command[0] = '0';
strcat(command,cmd_p1);
strcat(command,cmd_p2);
strcat(command,cmd_p3);
//usleep(line_number);
char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0";
strcat(command,cmd);
FILE *in;
in= popen(command, "r");
rewind(in);
char buff[50];
int counter = 0;
while(fgets(buff,sizeof(buff),in))
{
char c=' ';
int i = 0;
int cnt = atoi(buff);
arr[line_number-1].count[counter] = cnt;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+6];
i++;
}
int cnnt = 0;
while(c!=' ')
{
c = buff[cnnt];
cnnt++;
}
i=0;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+cnnt];
i++;
}
sprintf(arr[line_number-1].wordlist[counter],"%s",buff);
counter++;
}
arr[line_number-1].count[counter] = -1;
fclose(in);
return NULL;
}
int main(void)
{
FILE *fp;
fp = fopen("file.txt","r");
char a[200];
lines = 0;
void *status = NULL;
while(fgets(a,sizeof(a),fp) !=NULL)
{
lines++;
}
fclose(fp);
arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines);
threads = malloc(sizeof(pthread_t)*lines);
int i;
for(i=0;i= 0)
{
if(arr[i].count[ctr] > 0)
{
strcpy(final[final_ctr],arr[i].wordlist[ctr]);
final_cnt[final_ctr] = arr[i].count[ctr];
arr[i].count[ctr] = 0;
int sum = aggregate(arr[i].wordlist[ctr]);
final_cnt[final_ctr] += sum;
printf("%d %s",final_cnt[final_ctr],final[final_ctr]);
}
ctr++; final_ctr++;
}
i++;
if(i==lines)
{
break;
}
}
free(arr);
return 0;
}
#include
#include
#include
#include
/*Structure for storing words received from each thread*/
struct return_val{
char wordlist[100][100];
int count[100];
} *arr;
pthread_t *threads;
int lines;
/*Aggregates Frequency Sum of different threads*/
int aggregate(char *a)
{
int sum = 0;
int i=0;
while(1)
{
if(i==lines) break;
int count = 0;
while(1)
{
if(arr[i].count[count] == -1)
{
break;
}
if(strcmp(a,arr[i].wordlist[count]) == 0)
{
sum += arr[i].count[count];
arr[i].count[count] = 0;
}
count++;
}
i++;
}
return sum;
}
/*Function executed by each thread on separate line*/
void *word_count(void* num)
{
int *ln = num;
unsigned int line_number = *ln;
line_number++;
char cmd_p1[9] = "sed -n '0";
char cmd_p2[2];
sprintf(cmd_p2,"%d",line_number);
char cmd_p3[14] = "p' 'file.txt'0";
char command[100];
command[0] = '0';
strcat(command,cmd_p1);
strcat(command,cmd_p2);
strcat(command,cmd_p3);
//usleep(line_number);
char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0";
strcat(command,cmd);
FILE *in;
in= popen(command, "r");
rewind(in);
char buff[50];
int counter = 0;
while(fgets(buff,sizeof(buff),in))
{
char c=' ';
int i = 0;
int cnt = atoi(buff);
arr[line_number-1].count[counter] = cnt;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+6];
i++;
}
int cnnt = 0;
while(c!=' ')
{
c = buff[cnnt];
cnnt++;
}
i=0;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+cnnt];
i++;
}
sprintf(arr[line_number-1].wordlist[counter],"%s",buff);
counter++;
}
arr[line_number-1].count[counter] = -1;
fclose(in);
return NULL;
}
int main(void)
{
FILE *fp;
fp = fopen("file.txt","r");
char a[200];
lines = 0;
void *status = NULL;
while(fgets(a,sizeof(a),fp) !=NULL)
{
lines++;
}
fclose(fp);
arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines);
threads = malloc(sizeof(pthread_t)*lines);
int i;
for(i=0;i= 0)
{
if(arr[i].count[ctr] > 0)
{
strcpy(final[final_ctr],arr[i].wordlist[ctr]);
final_cnt[final_ctr] = arr[i].count[ctr];
arr[i].count[ctr] = 0;
int sum = aggregate(arr[i].wordlist[ctr]);
final_cnt[final_ctr] += sum;
printf("%d %s",final_cnt[final_ctr],final[final_ctr]);
}
ctr++; final_ctr++;
}
i++;
if(i==lines)
{
break;
}
}
free(arr);
return 0;
}
Solution
#include
#include
#include
#include
/*Structure for storing words received from each thread*/
struct return_val{
char wordlist[100][100];
int count[100];
} *arr;
pthread_t *threads;
int lines;
/*Aggregates Frequency Sum of different threads*/
int aggregate(char *a)
{
int sum = 0;
int i=0;
while(1)
{
if(i==lines) break;
int count = 0;
while(1)
{
if(arr[i].count[count] == -1)
{
break;
}
if(strcmp(a,arr[i].wordlist[count]) == 0)
{
sum += arr[i].count[count];
arr[i].count[count] = 0;
}
count++;
}
i++;
}
return sum;
}
/*Function executed by each thread on separate line*/
void *word_count(void* num)
{
int *ln = num;
unsigned int line_number = *ln;
line_number++;
char cmd_p1[9] = "sed -n '0";
char cmd_p2[2];
sprintf(cmd_p2,"%d",line_number);
char cmd_p3[14] = "p' 'file.txt'0";
char command[100];
command[0] = '0';
strcat(command,cmd_p1);
strcat(command,cmd_p2);
strcat(command,cmd_p3);
//usleep(line_number);
char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0";
strcat(command,cmd);
FILE *in;
in= popen(command, "r");
rewind(in);
char buff[50];
int counter = 0;
while(fgets(buff,sizeof(buff),in))
{
char c=' ';
int i = 0;
int cnt = atoi(buff);
arr[line_number-1].count[counter] = cnt;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+6];
i++;
}
int cnnt = 0;
while(c!=' ')
{
c = buff[cnnt];
cnnt++;
}
i=0;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+cnnt];
i++;
}
sprintf(arr[line_number-1].wordlist[counter],"%s",buff);
counter++;
}
arr[line_number-1].count[counter] = -1;
fclose(in);
return NULL;
}
int main(void)
{
FILE *fp;
fp = fopen("file.txt","r");
char a[200];
lines = 0;
void *status = NULL;
while(fgets(a,sizeof(a),fp) !=NULL)
{
lines++;
}
fclose(fp);
arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines);
threads = malloc(sizeof(pthread_t)*lines);
int i;
for(i=0;i= 0)
{
if(arr[i].count[ctr] > 0)
{
strcpy(final[final_ctr],arr[i].wordlist[ctr]);
final_cnt[final_ctr] = arr[i].count[ctr];
arr[i].count[ctr] = 0;
int sum = aggregate(arr[i].wordlist[ctr]);
final_cnt[final_ctr] += sum;
printf("%d %s",final_cnt[final_ctr],final[final_ctr]);
}
ctr++; final_ctr++;
}
i++;
if(i==lines)
{
break;
}
}
free(arr);
return 0;
}
#include
#include
#include
#include
/*Structure for storing words received from each thread*/
struct return_val{
char wordlist[100][100];
int count[100];
} *arr;
pthread_t *threads;
int lines;
/*Aggregates Frequency Sum of different threads*/
int aggregate(char *a)
{
int sum = 0;
int i=0;
while(1)
{
if(i==lines) break;
int count = 0;
while(1)
{
if(arr[i].count[count] == -1)
{
break;
}
if(strcmp(a,arr[i].wordlist[count]) == 0)
{
sum += arr[i].count[count];
arr[i].count[count] = 0;
}
count++;
}
i++;
}
return sum;
}
/*Function executed by each thread on separate line*/
void *word_count(void* num)
{
int *ln = num;
unsigned int line_number = *ln;
line_number++;
char cmd_p1[9] = "sed -n '0";
char cmd_p2[2];
sprintf(cmd_p2,"%d",line_number);
char cmd_p3[14] = "p' 'file.txt'0";
char command[100];
command[0] = '0';
strcat(command,cmd_p1);
strcat(command,cmd_p2);
strcat(command,cmd_p3);
//usleep(line_number);
char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0";
strcat(command,cmd);
FILE *in;
in= popen(command, "r");
rewind(in);
char buff[50];
int counter = 0;
while(fgets(buff,sizeof(buff),in))
{
char c=' ';
int i = 0;
int cnt = atoi(buff);
arr[line_number-1].count[counter] = cnt;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+6];
i++;
}
int cnnt = 0;
while(c!=' ')
{
c = buff[cnnt];
cnnt++;
}
i=0;
while(c!='0')
{
c=buff[i];
buff[i]=buff[i+cnnt];
i++;
}
sprintf(arr[line_number-1].wordlist[counter],"%s",buff);
counter++;
}
arr[line_number-1].count[counter] = -1;
fclose(in);
return NULL;
}
int main(void)
{
FILE *fp;
fp = fopen("file.txt","r");
char a[200];
lines = 0;
void *status = NULL;
while(fgets(a,sizeof(a),fp) !=NULL)
{
lines++;
}
fclose(fp);
arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines);
threads = malloc(sizeof(pthread_t)*lines);
int i;
for(i=0;i= 0)
{
if(arr[i].count[ctr] > 0)
{
strcpy(final[final_ctr],arr[i].wordlist[ctr]);
final_cnt[final_ctr] = arr[i].count[ctr];
arr[i].count[ctr] = 0;
int sum = aggregate(arr[i].wordlist[ctr]);
final_cnt[final_ctr] += sum;
printf("%d %s",final_cnt[final_ctr],final[final_ctr]);
}
ctr++; final_ctr++;
}
i++;
if(i==lines)
{
break;
}
}
free(arr);
return 0;
}

More Related Content

Similar to #include stdio.h#include stdlib.h#include string.h#inclu.pdf

1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
rushabhshah600
 
4 operators, expressions & statements
4  operators, expressions & statements4  operators, expressions & statements
4 operators, expressions & statements
MomenMostafa
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
eyelineoptics
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Er Ritu Aggarwal
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
anujmkt
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
hasan0812
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
Cpds lab
Cpds labCpds lab
c programming
c programmingc programming
c programming
Arun Umrao
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
Arkadeep Dey
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
Eleanor McHugh
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
AkhilaaReddy
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
Han Lee
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
Adamq0DJonese
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdf
badshetoms
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 

Similar to #include stdio.h#include stdlib.h#include string.h#inclu.pdf (20)

1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
4 operators, expressions & statements
4  operators, expressions & statements4  operators, expressions & statements
4 operators, expressions & statements
 
The following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdfThe following is my code for a connectn program. When I run my code .pdf
The following is my code for a connectn program. When I run my code .pdf
 
C program
C programC program
C program
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
Program of sorting using shell sort #include stdio.h #de.pdf
 Program of sorting using shell sort  #include stdio.h #de.pdf Program of sorting using shell sort  #include stdio.h #de.pdf
Program of sorting using shell sort #include stdio.h #de.pdf
 
Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)Hangman Game Programming in C (coding)
Hangman Game Programming in C (coding)
 
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
week-6x
week-6xweek-6x
week-6x
 
c programming
c programmingc programming
c programming
 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
 
Implementing Software Machines in Go and C
Implementing Software Machines in Go and CImplementing Software Machines in Go and C
Implementing Software Machines in Go and C
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
-- Task 2- Debugging a program with stacks- queues- and doubly-linked.docx
 
C programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdfC programming.   For this code I only need to add a function so th.pdf
C programming.   For this code I only need to add a function so th.pdf
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 

More from apleather

pH = -log[H+] pH = -log(0.5) pH = 0.301 .pdf
                     pH = -log[H+]  pH = -log(0.5)  pH = 0.301        .pdf                     pH = -log[H+]  pH = -log(0.5)  pH = 0.301        .pdf
pH = -log[H+] pH = -log(0.5) pH = 0.301 .pdf
apleather
 
The universality of the genetic code provides strong support for the.pdf
The universality of the genetic code provides strong support for the.pdfThe universality of the genetic code provides strong support for the.pdf
The universality of the genetic code provides strong support for the.pdf
apleather
 
The pus is consists of neutrophils which target the pathogen. The pa.pdf
The pus is consists of neutrophils which target the pathogen. The pa.pdfThe pus is consists of neutrophils which target the pathogen. The pa.pdf
The pus is consists of neutrophils which target the pathogen. The pa.pdf
apleather
 
The least soluble gas is N2 because it is inert and cannot form any .pdf
The least soluble gas is N2 because it is inert and cannot form any .pdfThe least soluble gas is N2 because it is inert and cannot form any .pdf
The least soluble gas is N2 because it is inert and cannot form any .pdf
apleather
 
The below stated are the Challenges and business requirements faced .pdf
The below stated are the Challenges and business requirements faced .pdfThe below stated are the Challenges and business requirements faced .pdf
The below stated are the Challenges and business requirements faced .pdf
apleather
 
Sometimes CEO can also hold the position of Chairperson, but in some.pdf
Sometimes CEO can also hold the position of Chairperson, but in some.pdfSometimes CEO can also hold the position of Chairperson, but in some.pdf
Sometimes CEO can also hold the position of Chairperson, but in some.pdf
apleather
 
SolutionInorder traversal It will consider left child root, and .pdf
SolutionInorder traversal It will consider left child root, and .pdfSolutionInorder traversal It will consider left child root, and .pdf
SolutionInorder traversal It will consider left child root, and .pdf
apleather
 
In a side the length of sides are same. use this property iterativel.pdf
In a side the length of sides are same. use this property iterativel.pdfIn a side the length of sides are same. use this property iterativel.pdf
In a side the length of sides are same. use this property iterativel.pdf
apleather
 
Elements or steps of acceptance testingSolutionElements or ste.pdf
Elements or steps of acceptance testingSolutionElements or ste.pdfElements or steps of acceptance testingSolutionElements or ste.pdf
Elements or steps of acceptance testingSolutionElements or ste.pdf
apleather
 
Long term capital = Common stock + shareholders equity + Retained ea.pdf
Long term capital = Common stock + shareholders equity + Retained ea.pdfLong term capital = Common stock + shareholders equity + Retained ea.pdf
Long term capital = Common stock + shareholders equity + Retained ea.pdf
apleather
 
Limbs evolve so frequently that it is impossible to determine otherw.pdf
Limbs evolve so frequently that it is impossible to determine otherw.pdfLimbs evolve so frequently that it is impossible to determine otherw.pdf
Limbs evolve so frequently that it is impossible to determine otherw.pdf
apleather
 
hmmSolutionhmm.pdf
hmmSolutionhmm.pdfhmmSolutionhmm.pdf
hmmSolutionhmm.pdf
apleather
 
Form1.csusing System; using System.Collections.Generic; using .pdf
Form1.csusing System; using System.Collections.Generic; using .pdfForm1.csusing System; using System.Collections.Generic; using .pdf
Form1.csusing System; using System.Collections.Generic; using .pdf
apleather
 
Influenza A The recently raised awareness of th.pdf
                     Influenza A  The recently raised awareness of th.pdf                     Influenza A  The recently raised awareness of th.pdf
Influenza A The recently raised awareness of th.pdf
apleather
 
I believe its named Methyl iodide. You wouldn.pdf
                     I believe its named Methyl iodide. You wouldn.pdf                     I believe its named Methyl iodide. You wouldn.pdf
I believe its named Methyl iodide. You wouldn.pdf
apleather
 
Data warehousing has quickly evolved into a unique and popular busin.pdf
Data warehousing has quickly evolved into a unique and popular busin.pdfData warehousing has quickly evolved into a unique and popular busin.pdf
Data warehousing has quickly evolved into a unique and popular busin.pdf
apleather
 
balready postedSolutionbalready posted.pdf
balready postedSolutionbalready posted.pdfbalready postedSolutionbalready posted.pdf
balready postedSolutionbalready posted.pdf
apleather
 
Assume the graph is strongly connected.SolutionAssume the grap.pdf
Assume the graph is strongly connected.SolutionAssume the grap.pdfAssume the graph is strongly connected.SolutionAssume the grap.pdf
Assume the graph is strongly connected.SolutionAssume the grap.pdf
apleather
 
Half life is the time in which the compound reduc.pdf
                     Half life is the time in which the compound reduc.pdf                     Half life is the time in which the compound reduc.pdf
Half life is the time in which the compound reduc.pdf
apleather
 
from the given reaction, order NO3=1 overall orde.pdf
                     from the given reaction, order NO3=1 overall orde.pdf                     from the given reaction, order NO3=1 overall orde.pdf
from the given reaction, order NO3=1 overall orde.pdf
apleather
 

More from apleather (20)

pH = -log[H+] pH = -log(0.5) pH = 0.301 .pdf
                     pH = -log[H+]  pH = -log(0.5)  pH = 0.301        .pdf                     pH = -log[H+]  pH = -log(0.5)  pH = 0.301        .pdf
pH = -log[H+] pH = -log(0.5) pH = 0.301 .pdf
 
The universality of the genetic code provides strong support for the.pdf
The universality of the genetic code provides strong support for the.pdfThe universality of the genetic code provides strong support for the.pdf
The universality of the genetic code provides strong support for the.pdf
 
The pus is consists of neutrophils which target the pathogen. The pa.pdf
The pus is consists of neutrophils which target the pathogen. The pa.pdfThe pus is consists of neutrophils which target the pathogen. The pa.pdf
The pus is consists of neutrophils which target the pathogen. The pa.pdf
 
The least soluble gas is N2 because it is inert and cannot form any .pdf
The least soluble gas is N2 because it is inert and cannot form any .pdfThe least soluble gas is N2 because it is inert and cannot form any .pdf
The least soluble gas is N2 because it is inert and cannot form any .pdf
 
The below stated are the Challenges and business requirements faced .pdf
The below stated are the Challenges and business requirements faced .pdfThe below stated are the Challenges and business requirements faced .pdf
The below stated are the Challenges and business requirements faced .pdf
 
Sometimes CEO can also hold the position of Chairperson, but in some.pdf
Sometimes CEO can also hold the position of Chairperson, but in some.pdfSometimes CEO can also hold the position of Chairperson, but in some.pdf
Sometimes CEO can also hold the position of Chairperson, but in some.pdf
 
SolutionInorder traversal It will consider left child root, and .pdf
SolutionInorder traversal It will consider left child root, and .pdfSolutionInorder traversal It will consider left child root, and .pdf
SolutionInorder traversal It will consider left child root, and .pdf
 
In a side the length of sides are same. use this property iterativel.pdf
In a side the length of sides are same. use this property iterativel.pdfIn a side the length of sides are same. use this property iterativel.pdf
In a side the length of sides are same. use this property iterativel.pdf
 
Elements or steps of acceptance testingSolutionElements or ste.pdf
Elements or steps of acceptance testingSolutionElements or ste.pdfElements or steps of acceptance testingSolutionElements or ste.pdf
Elements or steps of acceptance testingSolutionElements or ste.pdf
 
Long term capital = Common stock + shareholders equity + Retained ea.pdf
Long term capital = Common stock + shareholders equity + Retained ea.pdfLong term capital = Common stock + shareholders equity + Retained ea.pdf
Long term capital = Common stock + shareholders equity + Retained ea.pdf
 
Limbs evolve so frequently that it is impossible to determine otherw.pdf
Limbs evolve so frequently that it is impossible to determine otherw.pdfLimbs evolve so frequently that it is impossible to determine otherw.pdf
Limbs evolve so frequently that it is impossible to determine otherw.pdf
 
hmmSolutionhmm.pdf
hmmSolutionhmm.pdfhmmSolutionhmm.pdf
hmmSolutionhmm.pdf
 
Form1.csusing System; using System.Collections.Generic; using .pdf
Form1.csusing System; using System.Collections.Generic; using .pdfForm1.csusing System; using System.Collections.Generic; using .pdf
Form1.csusing System; using System.Collections.Generic; using .pdf
 
Influenza A The recently raised awareness of th.pdf
                     Influenza A  The recently raised awareness of th.pdf                     Influenza A  The recently raised awareness of th.pdf
Influenza A The recently raised awareness of th.pdf
 
I believe its named Methyl iodide. You wouldn.pdf
                     I believe its named Methyl iodide. You wouldn.pdf                     I believe its named Methyl iodide. You wouldn.pdf
I believe its named Methyl iodide. You wouldn.pdf
 
Data warehousing has quickly evolved into a unique and popular busin.pdf
Data warehousing has quickly evolved into a unique and popular busin.pdfData warehousing has quickly evolved into a unique and popular busin.pdf
Data warehousing has quickly evolved into a unique and popular busin.pdf
 
balready postedSolutionbalready posted.pdf
balready postedSolutionbalready posted.pdfbalready postedSolutionbalready posted.pdf
balready postedSolutionbalready posted.pdf
 
Assume the graph is strongly connected.SolutionAssume the grap.pdf
Assume the graph is strongly connected.SolutionAssume the grap.pdfAssume the graph is strongly connected.SolutionAssume the grap.pdf
Assume the graph is strongly connected.SolutionAssume the grap.pdf
 
Half life is the time in which the compound reduc.pdf
                     Half life is the time in which the compound reduc.pdf                     Half life is the time in which the compound reduc.pdf
Half life is the time in which the compound reduc.pdf
 
from the given reaction, order NO3=1 overall orde.pdf
                     from the given reaction, order NO3=1 overall orde.pdf                     from the given reaction, order NO3=1 overall orde.pdf
from the given reaction, order NO3=1 overall orde.pdf
 

Recently uploaded

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

#include stdio.h#include stdlib.h#include string.h#inclu.pdf

  • 1. #include #include #include #include /*Structure for storing words received from each thread*/ struct return_val{ char wordlist[100][100]; int count[100]; } *arr; pthread_t *threads; int lines; /*Aggregates Frequency Sum of different threads*/ int aggregate(char *a) { int sum = 0; int i=0; while(1) { if(i==lines) break; int count = 0; while(1) { if(arr[i].count[count] == -1) { break; } if(strcmp(a,arr[i].wordlist[count]) == 0) { sum += arr[i].count[count]; arr[i].count[count] = 0; } count++;
  • 2. } i++; } return sum; } /*Function executed by each thread on separate line*/ void *word_count(void* num) { int *ln = num; unsigned int line_number = *ln; line_number++; char cmd_p1[9] = "sed -n '0"; char cmd_p2[2]; sprintf(cmd_p2,"%d",line_number); char cmd_p3[14] = "p' 'file.txt'0"; char command[100]; command[0] = '0'; strcat(command,cmd_p1); strcat(command,cmd_p2); strcat(command,cmd_p3); //usleep(line_number); char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0"; strcat(command,cmd); FILE *in; in= popen(command, "r"); rewind(in); char buff[50]; int counter = 0; while(fgets(buff,sizeof(buff),in))
  • 3. { char c=' '; int i = 0; int cnt = atoi(buff); arr[line_number-1].count[counter] = cnt; while(c!='0') { c=buff[i]; buff[i]=buff[i+6]; i++; } int cnnt = 0; while(c!=' ') { c = buff[cnnt]; cnnt++; } i=0; while(c!='0') { c=buff[i]; buff[i]=buff[i+cnnt]; i++; } sprintf(arr[line_number-1].wordlist[counter],"%s",buff); counter++; } arr[line_number-1].count[counter] = -1; fclose(in); return NULL;
  • 4. } int main(void) { FILE *fp; fp = fopen("file.txt","r"); char a[200]; lines = 0; void *status = NULL; while(fgets(a,sizeof(a),fp) !=NULL) { lines++; } fclose(fp); arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines); threads = malloc(sizeof(pthread_t)*lines); int i; for(i=0;i= 0) { if(arr[i].count[ctr] > 0) { strcpy(final[final_ctr],arr[i].wordlist[ctr]); final_cnt[final_ctr] = arr[i].count[ctr]; arr[i].count[ctr] = 0; int sum = aggregate(arr[i].wordlist[ctr]); final_cnt[final_ctr] += sum; printf("%d %s",final_cnt[final_ctr],final[final_ctr]); } ctr++; final_ctr++; }
  • 5. i++; if(i==lines) { break; } } free(arr); return 0; } #include #include #include #include /*Structure for storing words received from each thread*/ struct return_val{ char wordlist[100][100]; int count[100]; } *arr; pthread_t *threads; int lines; /*Aggregates Frequency Sum of different threads*/ int aggregate(char *a) { int sum = 0; int i=0; while(1) { if(i==lines) break; int count = 0; while(1) { if(arr[i].count[count] == -1) { break; }
  • 6. if(strcmp(a,arr[i].wordlist[count]) == 0) { sum += arr[i].count[count]; arr[i].count[count] = 0; } count++; } i++; } return sum; } /*Function executed by each thread on separate line*/ void *word_count(void* num) { int *ln = num; unsigned int line_number = *ln; line_number++; char cmd_p1[9] = "sed -n '0"; char cmd_p2[2]; sprintf(cmd_p2,"%d",line_number); char cmd_p3[14] = "p' 'file.txt'0"; char command[100]; command[0] = '0'; strcat(command,cmd_p1); strcat(command,cmd_p2); strcat(command,cmd_p3); //usleep(line_number);
  • 7. char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0"; strcat(command,cmd); FILE *in; in= popen(command, "r"); rewind(in); char buff[50]; int counter = 0; while(fgets(buff,sizeof(buff),in)) { char c=' '; int i = 0; int cnt = atoi(buff); arr[line_number-1].count[counter] = cnt; while(c!='0') { c=buff[i]; buff[i]=buff[i+6]; i++; } int cnnt = 0; while(c!=' ') { c = buff[cnnt]; cnnt++; } i=0; while(c!='0') { c=buff[i]; buff[i]=buff[i+cnnt]; i++; }
  • 8. sprintf(arr[line_number-1].wordlist[counter],"%s",buff); counter++; } arr[line_number-1].count[counter] = -1; fclose(in); return NULL; } int main(void) { FILE *fp; fp = fopen("file.txt","r"); char a[200]; lines = 0; void *status = NULL; while(fgets(a,sizeof(a),fp) !=NULL) { lines++; } fclose(fp); arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines); threads = malloc(sizeof(pthread_t)*lines); int i; for(i=0;i= 0) { if(arr[i].count[ctr] > 0) { strcpy(final[final_ctr],arr[i].wordlist[ctr]); final_cnt[final_ctr] = arr[i].count[ctr];
  • 9. arr[i].count[ctr] = 0; int sum = aggregate(arr[i].wordlist[ctr]); final_cnt[final_ctr] += sum; printf("%d %s",final_cnt[final_ctr],final[final_ctr]); } ctr++; final_ctr++; } i++; if(i==lines) { break; } } free(arr); return 0; } Solution #include #include #include #include /*Structure for storing words received from each thread*/ struct return_val{ char wordlist[100][100]; int count[100]; } *arr; pthread_t *threads; int lines; /*Aggregates Frequency Sum of different threads*/ int aggregate(char *a) {
  • 10. int sum = 0; int i=0; while(1) { if(i==lines) break; int count = 0; while(1) { if(arr[i].count[count] == -1) { break; } if(strcmp(a,arr[i].wordlist[count]) == 0) { sum += arr[i].count[count]; arr[i].count[count] = 0; } count++; } i++; } return sum; } /*Function executed by each thread on separate line*/ void *word_count(void* num) { int *ln = num; unsigned int line_number = *ln;
  • 11. line_number++; char cmd_p1[9] = "sed -n '0"; char cmd_p2[2]; sprintf(cmd_p2,"%d",line_number); char cmd_p3[14] = "p' 'file.txt'0"; char command[100]; command[0] = '0'; strcat(command,cmd_p1); strcat(command,cmd_p2); strcat(command,cmd_p3); //usleep(line_number); char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0"; strcat(command,cmd); FILE *in; in= popen(command, "r"); rewind(in); char buff[50]; int counter = 0; while(fgets(buff,sizeof(buff),in)) { char c=' '; int i = 0; int cnt = atoi(buff); arr[line_number-1].count[counter] = cnt; while(c!='0') { c=buff[i]; buff[i]=buff[i+6]; i++; } int cnnt = 0;
  • 12. while(c!=' ') { c = buff[cnnt]; cnnt++; } i=0; while(c!='0') { c=buff[i]; buff[i]=buff[i+cnnt]; i++; } sprintf(arr[line_number-1].wordlist[counter],"%s",buff); counter++; } arr[line_number-1].count[counter] = -1; fclose(in); return NULL; } int main(void) { FILE *fp; fp = fopen("file.txt","r"); char a[200]; lines = 0; void *status = NULL; while(fgets(a,sizeof(a),fp) !=NULL) { lines++; }
  • 13. fclose(fp); arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines); threads = malloc(sizeof(pthread_t)*lines); int i; for(i=0;i= 0) { if(arr[i].count[ctr] > 0) { strcpy(final[final_ctr],arr[i].wordlist[ctr]); final_cnt[final_ctr] = arr[i].count[ctr]; arr[i].count[ctr] = 0; int sum = aggregate(arr[i].wordlist[ctr]); final_cnt[final_ctr] += sum; printf("%d %s",final_cnt[final_ctr],final[final_ctr]); } ctr++; final_ctr++; } i++; if(i==lines) { break; } } free(arr); return 0; } #include #include #include #include /*Structure for storing words received from each thread*/
  • 14. struct return_val{ char wordlist[100][100]; int count[100]; } *arr; pthread_t *threads; int lines; /*Aggregates Frequency Sum of different threads*/ int aggregate(char *a) { int sum = 0; int i=0; while(1) { if(i==lines) break; int count = 0; while(1) { if(arr[i].count[count] == -1) { break; } if(strcmp(a,arr[i].wordlist[count]) == 0) { sum += arr[i].count[count]; arr[i].count[count] = 0; } count++; } i++; }
  • 15. return sum; } /*Function executed by each thread on separate line*/ void *word_count(void* num) { int *ln = num; unsigned int line_number = *ln; line_number++; char cmd_p1[9] = "sed -n '0"; char cmd_p2[2]; sprintf(cmd_p2,"%d",line_number); char cmd_p3[14] = "p' 'file.txt'0"; char command[100]; command[0] = '0'; strcat(command,cmd_p1); strcat(command,cmd_p2); strcat(command,cmd_p3); //usleep(line_number); char cmd[100] = " | tr [:space:] ' ' | grep -v '^s*$' | sort | uniq -c | sort0"; strcat(command,cmd); FILE *in; in= popen(command, "r"); rewind(in); char buff[50]; int counter = 0; while(fgets(buff,sizeof(buff),in)) { char c=' '; int i = 0; int cnt = atoi(buff); arr[line_number-1].count[counter] = cnt;
  • 16. while(c!='0') { c=buff[i]; buff[i]=buff[i+6]; i++; } int cnnt = 0; while(c!=' ') { c = buff[cnnt]; cnnt++; } i=0; while(c!='0') { c=buff[i]; buff[i]=buff[i+cnnt]; i++; } sprintf(arr[line_number-1].wordlist[counter],"%s",buff); counter++; } arr[line_number-1].count[counter] = -1; fclose(in); return NULL; } int main(void) { FILE *fp; fp = fopen("file.txt","r");
  • 17. char a[200]; lines = 0; void *status = NULL; while(fgets(a,sizeof(a),fp) !=NULL) { lines++; } fclose(fp); arr = (struct return_val*) calloc(lines, sizeof(struct return_val) * lines); threads = malloc(sizeof(pthread_t)*lines); int i; for(i=0;i= 0) { if(arr[i].count[ctr] > 0) { strcpy(final[final_ctr],arr[i].wordlist[ctr]); final_cnt[final_ctr] = arr[i].count[ctr]; arr[i].count[ctr] = 0; int sum = aggregate(arr[i].wordlist[ctr]); final_cnt[final_ctr] += sum; printf("%d %s",final_cnt[final_ctr],final[final_ctr]); } ctr++; final_ctr++; } i++; if(i==lines) { break; } }