SlideShare a Scribd company logo
1 of 4
Download to read offline
C code:
#include
int main(void)
{
FILE *infp, *outfp;
int ID,day,hr,i=1;
int Temp_ID,Total_hr;
int Line_No=0;
if ((infp = fopen("emp.txt", "r"))==NULL)
{
printf("Input file cannot be opened ");
return-1;
}
if ((outfp = fopen("out.txt", "w"))==NULL)
{
printf("Output file cannot be opened ");
return-1;
}
while(!feof(infp))
{
Line_No=Line_No+1;
fscanf(infp,"%d %d",&ID,&hr);
if(Line_No==1)
{
Temp_ID=ID;day=1;Total_hr=hr;
}
else
{
if(Temp_ID==ID)
{
day=day+1;
Total_hr=Total_hr+hr;
}
else
{
fprintf(outfp,"%d %d %d ",Temp_ID,day,Total_hr);
Temp_ID=ID;day=1;Total_hr=hr;
}
}
}
fprintf(outfp,"%d %d %d ",Temp_ID,day-1,Total_hr-hr);
fclose(infp);
fclose(outfp);
}
emp.txt:
11 2
11 8
11 5
15 10
18 4
18 16
20 23
20 11
out.txt:
11 3 15
15 1 10
18 2 20
20 2 34
Solution
C code:
#include
int main(void)
{
FILE *infp, *outfp;
int ID,day,hr,i=1;
int Temp_ID,Total_hr;
int Line_No=0;
if ((infp = fopen("emp.txt", "r"))==NULL)
{
printf("Input file cannot be opened ");
return-1;
}
if ((outfp = fopen("out.txt", "w"))==NULL)
{
printf("Output file cannot be opened ");
return-1;
}
while(!feof(infp))
{
Line_No=Line_No+1;
fscanf(infp,"%d %d",&ID,&hr);
if(Line_No==1)
{
Temp_ID=ID;day=1;Total_hr=hr;
}
else
{
if(Temp_ID==ID)
{
day=day+1;
Total_hr=Total_hr+hr;
}
else
{
fprintf(outfp,"%d %d %d ",Temp_ID,day,Total_hr);
Temp_ID=ID;day=1;Total_hr=hr;
}
}
}
fprintf(outfp,"%d %d %d ",Temp_ID,day-1,Total_hr-hr);
fclose(infp);
fclose(outfp);
}
emp.txt:
11 2
11 8
11 5
15 10
18 4
18 16
20 23
20 11
out.txt:
11 3 15
15 1 10
18 2 20
20 2 34

More Related Content

Similar to C code#include stdio.hint main(void) {     FILE infp, o.pdf

Unix And C
Unix And CUnix And C
Unix And CDr.Ravi
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)mrecedu
 
Add a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdfAdd a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdfinfo245627
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4Koshy Geoji
 
Lua by Ong Hean Kuan
Lua by Ong Hean KuanLua by Ong Hean Kuan
Lua by Ong Hean Kuanfossmy
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semesterDOSONKA Group
 
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdfnareshsonyericcson
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxGordonpACKellyb
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesRashidFaridChishti
 
I am writing a program in C and it takes the name of an input file l.pdf
I am writing a program in C and it takes the name of an input file l.pdfI am writing a program in C and it takes the name of an input file l.pdf
I am writing a program in C and it takes the name of an input file l.pdfeyeonsecuritysystems
 
Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02Md. Ashikur Rahman
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 

Similar to C code#include stdio.hint main(void) {     FILE infp, o.pdf (20)

Unix And C
Unix And CUnix And C
Unix And C
 
Unit5 (2)
Unit5 (2)Unit5 (2)
Unit5 (2)
 
C Language Unit-5
C Language Unit-5C Language Unit-5
C Language Unit-5
 
Usp
UspUsp
Usp
 
Add a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdfAdd a 3rd field help that contains a short help string for each of t.pdf
Add a 3rd field help that contains a short help string for each of t.pdf
 
C programs Set 4
C programs Set 4C programs Set 4
C programs Set 4
 
Lua by Ong Hean Kuan
Lua by Ong Hean KuanLua by Ong Hean Kuan
Lua by Ong Hean Kuan
 
Vcs26
Vcs26Vcs26
Vcs26
 
Network lap pgms 7th semester
Network lap pgms 7th semesterNetwork lap pgms 7th semester
Network lap pgms 7th semester
 
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
#includestdio.h#includestdlib.hint encrypt(void);int decry.pdf
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docxIN C LANGUAGE- I've been trying to finish this program for the last fe.docx
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
 
week-4x
week-4xweek-4x
week-4x
 
java programming
java programmingjava programming
java programming
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
I am writing a program in C and it takes the name of an input file l.pdf
I am writing a program in C and it takes the name of an input file l.pdfI am writing a program in C and it takes the name of an input file l.pdf
I am writing a program in C and it takes the name of an input file l.pdf
 
14. fiile io
14. fiile io14. fiile io
14. fiile io
 
Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02Cse115 lecture08repetitionstructures part02
Cse115 lecture08repetitionstructures part02
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 

More from ankitmobileshop235

- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdfankitmobileshop235
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdfankitmobileshop235
 
Two sp3 orbitals are filled by lone electron pair.pdf
                     Two sp3 orbitals are filled by lone electron pair.pdf                     Two sp3 orbitals are filled by lone electron pair.pdf
Two sp3 orbitals are filled by lone electron pair.pdfankitmobileshop235
 
X-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdfX-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdfankitmobileshop235
 
whether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdfwhether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdfankitmobileshop235
 
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfankitmobileshop235
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfankitmobileshop235
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfankitmobileshop235
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfankitmobileshop235
 
the OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdfthe OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdfankitmobileshop235
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfankitmobileshop235
 
Reflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdfReflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdfankitmobileshop235
 
Question not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdfQuestion not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdfankitmobileshop235
 
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdfPer my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdfankitmobileshop235
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfankitmobileshop235
 
null is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdfnull is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdfankitmobileshop235
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfankitmobileshop235
 
Ho there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdfHo there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdfankitmobileshop235
 
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdfH2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdfankitmobileshop235
 

More from ankitmobileshop235 (20)

- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
- You have to overcome the ionic forces of the CsI, the hydrogen bon.pdf
 
#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf#includeiostream struct node {    char value;    struct no.pdf
#includeiostream struct node {    char value;    struct no.pdf
 
Two sp3 orbitals are filled by lone electron pair.pdf
                     Two sp3 orbitals are filled by lone electron pair.pdf                     Two sp3 orbitals are filled by lone electron pair.pdf
Two sp3 orbitals are filled by lone electron pair.pdf
 
X-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdfX-Intercept is the value of x where cross x axis. Another name is .pdf
X-Intercept is the value of x where cross x axis. Another name is .pdf
 
whether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdfwhether or not the viruses is not used to classify viruses.Vir.pdf
whether or not the viruses is not used to classify viruses.Vir.pdf
 
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdfVi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
Vi may be a powerful text editor enclosed with most UNIX systems, ev.pdf
 
U.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdfU.S management is trained to provide the executives their own career.pdf
U.S management is trained to provide the executives their own career.pdf
 
There are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdfThere are many operating systemsReal-Time Operating SystemReal-t.pdf
There are many operating systemsReal-Time Operating SystemReal-t.pdf
 
The three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdfThe three major forms of business organizations are1. Sole Propri.pdf
The three major forms of business organizations are1. Sole Propri.pdf
 
the OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdfthe OSI model is an idea. it is abstract it has no value without imp.pdf
the OSI model is an idea. it is abstract it has no value without imp.pdf
 
The EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdfThe EVA metric effectively measures the amount of shareholder wealth.pdf
The EVA metric effectively measures the amount of shareholder wealth.pdf
 
Reflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdfReflection about the centre of the pentagon is not its symmetric and.pdf
Reflection about the centre of the pentagon is not its symmetric and.pdf
 
Question not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdfQuestion not visible. Please state again.SolutionQuestion not .pdf
Question not visible. Please state again.SolutionQuestion not .pdf
 
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdfPer my quiz, it was also D) formation of the carbocatio or bromonium.pdf
Per my quiz, it was also D) formation of the carbocatio or bromonium.pdf
 
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdfPart ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
Part ATay-Sachs disease is an autosomal recessive disorder, so, o.pdf
 
null is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdfnull is a subset of every setTrueSolutionnull is a sub.pdf
null is a subset of every setTrueSolutionnull is a sub.pdf
 
LiOH Sol.pdf
                     LiOH                                      Sol.pdf                     LiOH                                      Sol.pdf
LiOH Sol.pdf
 
Information is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdfInformation is a valuable asset that can make or break your business.pdf
Information is a valuable asset that can make or break your business.pdf
 
Ho there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdfHo there is no relationship between the age of the individual and t.pdf
Ho there is no relationship between the age of the individual and t.pdf
 
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdfH2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
H2SO3 - H2O = SO2The oxide is sulfur dioxide SO2SolutionH2.pdf
 

Recently uploaded

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 

Recently uploaded (20)

Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 

C code#include stdio.hint main(void) {     FILE infp, o.pdf

  • 1. C code: #include int main(void) { FILE *infp, *outfp; int ID,day,hr,i=1; int Temp_ID,Total_hr; int Line_No=0; if ((infp = fopen("emp.txt", "r"))==NULL) { printf("Input file cannot be opened "); return-1; } if ((outfp = fopen("out.txt", "w"))==NULL) { printf("Output file cannot be opened "); return-1; } while(!feof(infp)) { Line_No=Line_No+1; fscanf(infp,"%d %d",&ID,&hr); if(Line_No==1) { Temp_ID=ID;day=1;Total_hr=hr; } else { if(Temp_ID==ID) { day=day+1; Total_hr=Total_hr+hr; } else {
  • 2. fprintf(outfp,"%d %d %d ",Temp_ID,day,Total_hr); Temp_ID=ID;day=1;Total_hr=hr; } } } fprintf(outfp,"%d %d %d ",Temp_ID,day-1,Total_hr-hr); fclose(infp); fclose(outfp); } emp.txt: 11 2 11 8 11 5 15 10 18 4 18 16 20 23 20 11 out.txt: 11 3 15 15 1 10 18 2 20 20 2 34 Solution C code: #include int main(void) { FILE *infp, *outfp; int ID,day,hr,i=1; int Temp_ID,Total_hr; int Line_No=0; if ((infp = fopen("emp.txt", "r"))==NULL) {
  • 3. printf("Input file cannot be opened "); return-1; } if ((outfp = fopen("out.txt", "w"))==NULL) { printf("Output file cannot be opened "); return-1; } while(!feof(infp)) { Line_No=Line_No+1; fscanf(infp,"%d %d",&ID,&hr); if(Line_No==1) { Temp_ID=ID;day=1;Total_hr=hr; } else { if(Temp_ID==ID) { day=day+1; Total_hr=Total_hr+hr; } else { fprintf(outfp,"%d %d %d ",Temp_ID,day,Total_hr); Temp_ID=ID;day=1;Total_hr=hr; } } } fprintf(outfp,"%d %d %d ",Temp_ID,day-1,Total_hr-hr); fclose(infp); fclose(outfp); } emp.txt: 11 2
  • 4. 11 8 11 5 15 10 18 4 18 16 20 23 20 11 out.txt: 11 3 15 15 1 10 18 2 20 20 2 34