SlideShare a Scribd company logo
1 of 3
Download to read offline
Q2: Write a C program called myupper4.c to take as command line input a file name. It should
then read the text file, one string at a time and store in a linked list each string. Each new string
read from the file should be inserted at the END of the linked list. Each node of the linked list
should contain 2 variables: i) a character array to hold a string, ii) a pointer to the next node in
the linked list. The myupper4.c file should also contain a function void print_linked_list(struct
*node) to iterate over the linked list and print the strings stored in each node of the linked list.
Solution
#include
#include
#include
#define MAX_LENGTH 512 // buffer size
typedef struct node
{
char data[MAX_LENGTH];
struct node *next;
} strNode;
int main ( int argc, char *argv[] )
{
strNode *head;
strNode *current;
if ( argc != 2 ) /* argc should be 2 for correct execution */
{
/* Assuming argv[0] it is the program name */
printf( "Error in %s filename", argv[0] );
exit();
}
else
{
// argv[1] is a filename to open
FILE *file = fopen( argv[1], "r" );
/* fopen returns 0 on failure */
if ( file == 0 )
{
printf( "Could not open file " );
}
else
{
char str[MAX_LENGTH];
/* read one word at a time from file, stopping at EOF,
indicating the end of the file. */
while ( fgets(str,sizeof str,file)!=NULL )
{
// check if list is empty
if (head == NULL)
{
head = (strNode*) malloc(sizeof(strNode)); // create head node
strcpy(head->data, str);
}
// if list not empty
else
{
current = head; // start at the beginning
while (current->next != NULL)
{
current = current->next; // traverse to the end of the list
}
current->next = (strNode*) malloc(sizeof(strNode));
current = current->next;
strcpy(current->data, str);
display(current);
}
}
fclose( file );
}
}
return 0;
}
void display(struct node *disp)
{
printf("%s ", disp->data);
if (disp->next == NULL)
{
return;
}
display(disp->next);
}

More Related Content

Similar to Q2 Write a C program called myupper4.c to take as command line inpu.pdf

IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfaratextails30
 
Read write program
Read write programRead write program
Read write programAMI AMITO
 
Programming in C
Programming in CProgramming in C
Programming in Csujathavvv
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfjillisacebi75827
 
C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHBhavsingh Maloth
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfMalligaarjunanN
 
file handling1
file handling1file handling1
file handling1student
 
File Handling in c.ppt
File Handling in c.pptFile Handling in c.ppt
File Handling in c.pptBhumaNagaPavan
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfsangeeta borde
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examplesMuhammed Thanveer M
 

Similar to Q2 Write a C program called myupper4.c to take as command line inpu.pdf (20)

Module 5 file cp
Module 5 file cpModule 5 file cp
Module 5 file cp
 
IN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdfIN C++ languageWrite a simple word processor that will accept text.pdf
IN C++ languageWrite a simple word processor that will accept text.pdf
 
Read write program
Read write programRead write program
Read write program
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Programming in C
Programming in CProgramming in C
Programming in C
 
Write a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdfWrite a C++ program 1. Study the function process_text() in file.pdf
Write a C++ program 1. Study the function process_text() in file.pdf
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
Unix lab
Unix labUnix lab
Unix lab
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
ppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdfppt5-190810161800 (1).pdf
ppt5-190810161800 (1).pdf
 
file handling1
file handling1file handling1
file handling1
 
Unit5
Unit5Unit5
Unit5
 
Satz1
Satz1Satz1
Satz1
 
File Handling in c.ppt
File Handling in c.pptFile Handling in c.ppt
File Handling in c.ppt
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdfAdvance C Programming UNIT 4-FILE HANDLING IN C.pdf
Advance C Programming UNIT 4-FILE HANDLING IN C.pdf
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
Unit 5 dwqb ans
Unit 5 dwqb ansUnit 5 dwqb ans
Unit 5 dwqb ans
 
Understanding c file handling functions with examples
Understanding c file handling functions with examplesUnderstanding c file handling functions with examples
Understanding c file handling functions with examples
 
File management
File managementFile management
File management
 

More from boothlynntur11512

Lean methodology as it is practiced today can be traced back to Mot.pdf
Lean methodology as it is practiced today can be traced back to  Mot.pdfLean methodology as it is practiced today can be traced back to  Mot.pdf
Lean methodology as it is practiced today can be traced back to Mot.pdfboothlynntur11512
 
is about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfis about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfboothlynntur11512
 
In C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfIn C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfboothlynntur11512
 
How important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfHow important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfboothlynntur11512
 
give me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfgive me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfboothlynntur11512
 
explain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfexplain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfboothlynntur11512
 
Discuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfDiscuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfboothlynntur11512
 
Define the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfDefine the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfboothlynntur11512
 
Describe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfDescribe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfboothlynntur11512
 
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfCousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfboothlynntur11512
 
Create two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfCreate two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfboothlynntur11512
 
Chrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfChrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfboothlynntur11512
 
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfChapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfboothlynntur11512
 
×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdfboothlynntur11512
 
You are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfYou are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfboothlynntur11512
 
Write a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfWrite a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfboothlynntur11512
 
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfWhy is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfboothlynntur11512
 
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfWhich of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfboothlynntur11512
 
Which of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfWhich of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfboothlynntur11512
 
What is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfWhat is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfboothlynntur11512
 

More from boothlynntur11512 (20)

Lean methodology as it is practiced today can be traced back to Mot.pdf
Lean methodology as it is practiced today can be traced back to  Mot.pdfLean methodology as it is practiced today can be traced back to  Mot.pdf
Lean methodology as it is practiced today can be traced back to Mot.pdf
 
is about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdfis about coping with complexity andis about coping with c.pdf
is about coping with complexity andis about coping with c.pdf
 
In C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdfIn C program, how to write two short programs one which hides a sho.pdf
In C program, how to write two short programs one which hides a sho.pdf
 
How important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdfHow important is cloud for GraybarSolution You may have.pdf
How important is cloud for GraybarSolution You may have.pdf
 
give me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdfgive me a list of positive risk factors for a charitySolutiont.pdf
give me a list of positive risk factors for a charitySolutiont.pdf
 
explain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdfexplain in details, auditing and its importanceSolutionANSWER.pdf
explain in details, auditing and its importanceSolutionANSWER.pdf
 
Discuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdfDiscuss the differences between attributes and characteristics of sy.pdf
Discuss the differences between attributes and characteristics of sy.pdf
 
Define the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdfDefine the terminology (10 words) common to the immune system and th.pdf
Define the terminology (10 words) common to the immune system and th.pdf
 
Describe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdfDescribe five robot application areas for vision systems. (Select fiv.pdf
Describe five robot application areas for vision systems. (Select fiv.pdf
 
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdfCousin Vinnie is a shareholder and an employee in the family busines.pdf
Cousin Vinnie is a shareholder and an employee in the family busines.pdf
 
Create two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdfCreate two linked lists each having eight nodes…..the first list has.pdf
Create two linked lists each having eight nodes…..the first list has.pdf
 
Chrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdfChrome File Edit View History Bookmarks People Window He.pdf
Chrome File Edit View History Bookmarks People Window He.pdf
 
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdfChapter 12 Information Systems, Read this book Computer Science Illu.pdf
Chapter 12 Information Systems, Read this book Computer Science Illu.pdf
 
×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf×y Connect nect Securehttpsnewcon connect.html 11.pdf
×y Connect nect Securehttpsnewcon connect.html 11.pdf
 
You are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdfYou are instructing a class of high school students on different wir.pdf
You are instructing a class of high school students on different wir.pdf
 
Write a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdfWrite a Java program that creates a drawing area of appropriate size.pdf
Write a Java program that creates a drawing area of appropriate size.pdf
 
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdfWhy is it that bacterial ribosomes can begin translation before mRNA .pdf
Why is it that bacterial ribosomes can begin translation before mRNA .pdf
 
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdfWhich of the statements below is FALSE 1 Common stocks ownership c.pdf
Which of the statements below is FALSE 1 Common stocks ownership c.pdf
 
Which of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdfWhich of the following is NOT part of the information about foreign o.pdf
Which of the following is NOT part of the information about foreign o.pdf
 
What is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdfWhat is the yield curve Why is the yield curve considered a leading.pdf
What is the yield curve Why is the yield curve considered a leading.pdf
 

Recently uploaded

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationNeilDeclaro1
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Recently uploaded (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Q2 Write a C program called myupper4.c to take as command line inpu.pdf

  • 1. Q2: Write a C program called myupper4.c to take as command line input a file name. It should then read the text file, one string at a time and store in a linked list each string. Each new string read from the file should be inserted at the END of the linked list. Each node of the linked list should contain 2 variables: i) a character array to hold a string, ii) a pointer to the next node in the linked list. The myupper4.c file should also contain a function void print_linked_list(struct *node) to iterate over the linked list and print the strings stored in each node of the linked list. Solution #include #include #include #define MAX_LENGTH 512 // buffer size typedef struct node { char data[MAX_LENGTH]; struct node *next; } strNode; int main ( int argc, char *argv[] ) { strNode *head; strNode *current; if ( argc != 2 ) /* argc should be 2 for correct execution */ { /* Assuming argv[0] it is the program name */ printf( "Error in %s filename", argv[0] ); exit(); } else { // argv[1] is a filename to open FILE *file = fopen( argv[1], "r" ); /* fopen returns 0 on failure */ if ( file == 0 )
  • 2. { printf( "Could not open file " ); } else { char str[MAX_LENGTH]; /* read one word at a time from file, stopping at EOF, indicating the end of the file. */ while ( fgets(str,sizeof str,file)!=NULL ) { // check if list is empty if (head == NULL) { head = (strNode*) malloc(sizeof(strNode)); // create head node strcpy(head->data, str); } // if list not empty else { current = head; // start at the beginning while (current->next != NULL) { current = current->next; // traverse to the end of the list } current->next = (strNode*) malloc(sizeof(strNode)); current = current->next; strcpy(current->data, str); display(current); } } fclose( file ); } } return 0; } void display(struct node *disp)
  • 3. { printf("%s ", disp->data); if (disp->next == NULL) { return; } display(disp->next); }