SlideShare a Scribd company logo
1 of 2
Download to read offline
include getopt in this code with the usage % doublesort [-d] [-o output_file_name] input_file_name:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
typedef struct node {
char* data;
struct node* prev;
struct node* next;
} Node;
Node* create_node(char* data) {
Node* new_node = malloc(sizeof(Node));
new_node->data = malloc(strlen(data) + 1);
strcpy(new_node->data, data);
new_node->prev = NULL;
new_node->next = NULL;
return new_node;
}
void insert_node(Node** head, Node* new_node) {
if (*head == NULL) {
*head = new_node;
return;
}
Node* current_node = *head;
while (current_node->next != NULL && strcmp(new_node->data, current_node->data) > 0) {
current_node = current_node->next;
}
if (current_node->next == NULL && strcmp(new_node->data, current_node->data) > 0) {
current_node->next = new_node;
new_node->prev = current_node;
return;
}
Node* prev_node = current_node->prev;
if (prev_node == NULL) {
*head = new_node;
} else {
prev_node->next = new_node;
}
new_node->prev = prev_node;
new_node->next = current_node;
current_node->prev = new_node;
}
void print_list(Node* head, FILE* output_file) {
while (head != NULL) {
fprintf(output_file, "%sn", head->data);
head = head->next;
}
}
void convert_to_lowercase(char* string) {
for (int i = 0; string[i]; i++) {
string[i] = tolower(string[i]);
}
}
int main(int argc, char* argv[]) {
if (argc != 2) {
printf("Usage: %s input_filen", argv[0]);
return 1;
}
FILE* input_file = fopen(argv[1], "r");
if (input_file == NULL) {
printf("Could not open file %sn", argv[1]);
return 1;
}
Node* head = NULL;
char buffer[100];
while (fgets(buffer, sizeof(buffer), input_file)) {
char* token = strtok(buffer, " tn");
while (token != NULL) {
convert_to_lowercase(token);
Node* new_node = create_node(token);
insert_node(&head, new_node);
token = strtok(NULL, " tn");
}
}
fclose(input_file);
print_list(head, stdout);
return 0;
}

More Related Content

Similar to include getopt in this code with the usage doublesort d.pdf

C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3ecomputernotes
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked listSourav Gayen
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfalphaagenciesindia
 
This code currently works. Run it and get a screen shot of its ou.docx
 This code currently works. Run it and get a screen shot of its ou.docx This code currently works. Run it and get a screen shot of its ou.docx
This code currently works. Run it and get a screen shot of its ou.docxKomlin1
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfwasemanivytreenrco51
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad balochSarmad Baloch
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfbermanbeancolungak45
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdfANJALIENTERPRISES1
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfaassecuritysystem
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docxacarolyn
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfarjunenterprises1978
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfajaycosmeticslg
 

Similar to include getopt in this code with the usage doublesort d.pdf (20)

C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
C program to insert a node in doubly linked list
C program to insert a node in doubly linked listC program to insert a node in doubly linked list
C program to insert a node in doubly linked list
 
Rewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdfRewrite this code so it can use a generic type instead of integers. .pdf
Rewrite this code so it can use a generic type instead of integers. .pdf
 
DS Code (CWH).docx
DS Code (CWH).docxDS Code (CWH).docx
DS Code (CWH).docx
 
This code currently works. Run it and get a screen shot of its ou.docx
 This code currently works. Run it and get a screen shot of its ou.docx This code currently works. Run it and get a screen shot of its ou.docx
This code currently works. Run it and get a screen shot of its ou.docx
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
 
I want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdfI want help in the following C++ programming task. Please do coding .pdf
I want help in the following C++ programming task. Please do coding .pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
C++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdfC++Write a method Node Nodereverse() which reverses a list..pdf
C++Write a method Node Nodereverse() which reverses a list..pdf
 
Please write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdfPlease write in C++ and should be able to compile and debug.Thank yo.pdf
Please write in C++ and should be able to compile and debug.Thank yo.pdf
 

More from adisainternational

Insert a function in cell D11 to display the ltem name based.pdf
Insert a function in cell D11 to display the ltem name based.pdfInsert a function in cell D11 to display the ltem name based.pdf
Insert a function in cell D11 to display the ltem name based.pdfadisainternational
 
Insert Document To Collection nbdaproject36vents VIEW P.pdf
Insert Document To Collection nbdaproject36vents VIEW  P.pdfInsert Document To Collection nbdaproject36vents VIEW  P.pdf
Insert Document To Collection nbdaproject36vents VIEW P.pdfadisainternational
 
innervates posterior 13 of tongue taste 2 Wordscran.pdf
innervates posterior 13 of tongue  taste  2 Wordscran.pdfinnervates posterior 13 of tongue  taste  2 Wordscran.pdf
innervates posterior 13 of tongue taste 2 Wordscran.pdfadisainternational
 
Individually look for the Code of Conduct of a selected comp.pdf
Individually look for the Code of Conduct of a selected comp.pdfIndividually look for the Code of Conduct of a selected comp.pdf
Individually look for the Code of Conduct of a selected comp.pdfadisainternational
 
Influenza is an infectious respiratory disease caused by a .pdf
Influenza is an infectious respiratory disease caused by a .pdfInfluenza is an infectious respiratory disease caused by a .pdf
Influenza is an infectious respiratory disease caused by a .pdfadisainternational
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfadisainternational
 
Informacin general Anna ha estado hablando con los director.pdf
Informacin general Anna ha estado hablando con los director.pdfInformacin general Anna ha estado hablando con los director.pdf
Informacin general Anna ha estado hablando con los director.pdfadisainternational
 
inflation in india interest rates in india and compare it wi.pdf
inflation in india interest rates in india and compare it wi.pdfinflation in india interest rates in india and compare it wi.pdf
inflation in india interest rates in india and compare it wi.pdfadisainternational
 
Indigenous Peoples and Environmental Sustainability Article .pdf
Indigenous Peoples and Environmental Sustainability Article .pdfIndigenous Peoples and Environmental Sustainability Article .pdf
Indigenous Peoples and Environmental Sustainability Article .pdfadisainternational
 
Information Security Problem a Give the public and private.pdf
Information Security Problem a Give the public and private.pdfInformation Security Problem a Give the public and private.pdf
Information Security Problem a Give the public and private.pdfadisainternational
 
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdf
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdfInfertility and Hypothyroidism Patient ProfileMB is a 29y.pdf
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdfadisainternational
 
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdf
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdfinet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdf
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdfadisainternational
 
Indique el diagnstico ms preciso posible Luego indique la.pdf
Indique el diagnstico ms preciso posible Luego indique la.pdfIndique el diagnstico ms preciso posible Luego indique la.pdf
Indique el diagnstico ms preciso posible Luego indique la.pdfadisainternational
 
In user interface design what is typically TRUE Group of a.pdf
In user interface design what is typically TRUE Group of a.pdfIn user interface design what is typically TRUE Group of a.pdf
In user interface design what is typically TRUE Group of a.pdfadisainternational
 
include ltinitializer_listgt include ltiostreamgt .pdf
include ltinitializer_listgt include ltiostreamgt .pdfinclude ltinitializer_listgt include ltiostreamgt .pdf
include ltinitializer_listgt include ltiostreamgt .pdfadisainternational
 
In your opinion What would drive your decisions If you wer.pdf
In your opinion What would drive your decisions If you wer.pdfIn your opinion What would drive your decisions If you wer.pdf
In your opinion What would drive your decisions If you wer.pdfadisainternational
 
Income statement for 2016 Sales are expected to increase by .pdf
Income statement for 2016 Sales are expected to increase by .pdfIncome statement for 2016 Sales are expected to increase by .pdf
Income statement for 2016 Sales are expected to increase by .pdfadisainternational
 
Indicate in the figure below the location of the Stratosphe.pdf
Indicate in the figure below the location of the Stratosphe.pdfIndicate in the figure below the location of the Stratosphe.pdf
Indicate in the figure below the location of the Stratosphe.pdfadisainternational
 
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdf
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdfIndependent ttest Dependentpaired ttest Oneway ANOVA Two.pdf
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdfadisainternational
 
Independent Assortment Two genes Dumb d and Anxious a .pdf
Independent Assortment Two genes Dumb d and Anxious a .pdfIndependent Assortment Two genes Dumb d and Anxious a .pdf
Independent Assortment Two genes Dumb d and Anxious a .pdfadisainternational
 

More from adisainternational (20)

Insert a function in cell D11 to display the ltem name based.pdf
Insert a function in cell D11 to display the ltem name based.pdfInsert a function in cell D11 to display the ltem name based.pdf
Insert a function in cell D11 to display the ltem name based.pdf
 
Insert Document To Collection nbdaproject36vents VIEW P.pdf
Insert Document To Collection nbdaproject36vents VIEW  P.pdfInsert Document To Collection nbdaproject36vents VIEW  P.pdf
Insert Document To Collection nbdaproject36vents VIEW P.pdf
 
innervates posterior 13 of tongue taste 2 Wordscran.pdf
innervates posterior 13 of tongue  taste  2 Wordscran.pdfinnervates posterior 13 of tongue  taste  2 Wordscran.pdf
innervates posterior 13 of tongue taste 2 Wordscran.pdf
 
Individually look for the Code of Conduct of a selected comp.pdf
Individually look for the Code of Conduct of a selected comp.pdfIndividually look for the Code of Conduct of a selected comp.pdf
Individually look for the Code of Conduct of a selected comp.pdf
 
Influenza is an infectious respiratory disease caused by a .pdf
Influenza is an infectious respiratory disease caused by a .pdfInfluenza is an infectious respiratory disease caused by a .pdf
Influenza is an infectious respiratory disease caused by a .pdf
 
include ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdfinclude ltstdiohgt include ltstdlibhgt include .pdf
include ltstdiohgt include ltstdlibhgt include .pdf
 
Informacin general Anna ha estado hablando con los director.pdf
Informacin general Anna ha estado hablando con los director.pdfInformacin general Anna ha estado hablando con los director.pdf
Informacin general Anna ha estado hablando con los director.pdf
 
inflation in india interest rates in india and compare it wi.pdf
inflation in india interest rates in india and compare it wi.pdfinflation in india interest rates in india and compare it wi.pdf
inflation in india interest rates in india and compare it wi.pdf
 
Indigenous Peoples and Environmental Sustainability Article .pdf
Indigenous Peoples and Environmental Sustainability Article .pdfIndigenous Peoples and Environmental Sustainability Article .pdf
Indigenous Peoples and Environmental Sustainability Article .pdf
 
Information Security Problem a Give the public and private.pdf
Information Security Problem a Give the public and private.pdfInformation Security Problem a Give the public and private.pdf
Information Security Problem a Give the public and private.pdf
 
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdf
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdfInfertility and Hypothyroidism Patient ProfileMB is a 29y.pdf
Infertility and Hypothyroidism Patient ProfileMB is a 29y.pdf
 
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdf
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdfinet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdf
inet at pemoning Bret is Bhen the nol asd atenene irpuinise .pdf
 
Indique el diagnstico ms preciso posible Luego indique la.pdf
Indique el diagnstico ms preciso posible Luego indique la.pdfIndique el diagnstico ms preciso posible Luego indique la.pdf
Indique el diagnstico ms preciso posible Luego indique la.pdf
 
In user interface design what is typically TRUE Group of a.pdf
In user interface design what is typically TRUE Group of a.pdfIn user interface design what is typically TRUE Group of a.pdf
In user interface design what is typically TRUE Group of a.pdf
 
include ltinitializer_listgt include ltiostreamgt .pdf
include ltinitializer_listgt include ltiostreamgt .pdfinclude ltinitializer_listgt include ltiostreamgt .pdf
include ltinitializer_listgt include ltiostreamgt .pdf
 
In your opinion What would drive your decisions If you wer.pdf
In your opinion What would drive your decisions If you wer.pdfIn your opinion What would drive your decisions If you wer.pdf
In your opinion What would drive your decisions If you wer.pdf
 
Income statement for 2016 Sales are expected to increase by .pdf
Income statement for 2016 Sales are expected to increase by .pdfIncome statement for 2016 Sales are expected to increase by .pdf
Income statement for 2016 Sales are expected to increase by .pdf
 
Indicate in the figure below the location of the Stratosphe.pdf
Indicate in the figure below the location of the Stratosphe.pdfIndicate in the figure below the location of the Stratosphe.pdf
Indicate in the figure below the location of the Stratosphe.pdf
 
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdf
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdfIndependent ttest Dependentpaired ttest Oneway ANOVA Two.pdf
Independent ttest Dependentpaired ttest Oneway ANOVA Two.pdf
 
Independent Assortment Two genes Dumb d and Anxious a .pdf
Independent Assortment Two genes Dumb d and Anxious a .pdfIndependent Assortment Two genes Dumb d and Anxious a .pdf
Independent Assortment Two genes Dumb d and Anxious a .pdf
 

Recently uploaded

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Recently uploaded (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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Ữ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

include getopt in this code with the usage doublesort d.pdf

  • 1. include getopt in this code with the usage % doublesort [-d] [-o output_file_name] input_file_name: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct node { char* data; struct node* prev; struct node* next; } Node; Node* create_node(char* data) { Node* new_node = malloc(sizeof(Node)); new_node->data = malloc(strlen(data) + 1); strcpy(new_node->data, data); new_node->prev = NULL; new_node->next = NULL; return new_node; } void insert_node(Node** head, Node* new_node) { if (*head == NULL) { *head = new_node; return; } Node* current_node = *head; while (current_node->next != NULL && strcmp(new_node->data, current_node->data) > 0) { current_node = current_node->next; } if (current_node->next == NULL && strcmp(new_node->data, current_node->data) > 0) { current_node->next = new_node; new_node->prev = current_node; return; } Node* prev_node = current_node->prev; if (prev_node == NULL) { *head = new_node; } else { prev_node->next = new_node; } new_node->prev = prev_node; new_node->next = current_node; current_node->prev = new_node; }
  • 2. void print_list(Node* head, FILE* output_file) { while (head != NULL) { fprintf(output_file, "%sn", head->data); head = head->next; } } void convert_to_lowercase(char* string) { for (int i = 0; string[i]; i++) { string[i] = tolower(string[i]); } } int main(int argc, char* argv[]) { if (argc != 2) { printf("Usage: %s input_filen", argv[0]); return 1; } FILE* input_file = fopen(argv[1], "r"); if (input_file == NULL) { printf("Could not open file %sn", argv[1]); return 1; } Node* head = NULL; char buffer[100]; while (fgets(buffer, sizeof(buffer), input_file)) { char* token = strtok(buffer, " tn"); while (token != NULL) { convert_to_lowercase(token); Node* new_node = create_node(token); insert_node(&head, new_node); token = strtok(NULL, " tn"); } } fclose(input_file); print_list(head, stdout); return 0; }