include getopt in this code with the usage doublesort [-d] [-o out.pdf

include getopt in this code with the usage % doublesort [-d] [-o output_file_name] input_file_name: #include #include #include #include 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, "%s\n", 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_file\n", argv[0]); return 1; } FILE* input_file = fopen(argv[1], "r"); if (input_file == NULL) { printf("Could not open file %s\n", argv[1]); return 1; } Node* head = NULL; char buffer[100]; while (fgets(buffer, sizeof(buffer), input_file)) { char* token = strtok(buffer, " \t\n"); while (token != NULL) { convert_to_lowercase(token); Node* new_node = create_node(token); insert_node(&head, new_node); token = strtok(NULL, " \t\n"); } } fclose(input_file); print_list(head, stdout); return 0; }.

include getopt in this code with the usage % doublesort [-d] [-o output_file_name]
input_file_name:
#include
#include
#include
#include
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;
}

Recomendados

include getopt in this code with the usage doublesort d.pdf por
include getopt in this code with the usage  doublesort d.pdfinclude getopt in this code with the usage  doublesort d.pdf
include getopt in this code with the usage doublesort d.pdfadisainternational
4 visualizações2 slides
Lab Week 2 Game Programming.docx por
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
18 visualizações13 slides
C program to insert a node in doubly linked list por
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
211 visualizações6 slides
coding in C- Create a function called reverseList that takes the head.docx por
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxtienlivick
3 visualizações3 slides
#include stdafx.h #include iostream using namespace std;vo.docx por
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docxajoy21
2 visualizações8 slides
C code on linked list #include stdio.h #include stdlib.h.pdf por
 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
2 visualizações4 slides

Mais conteúdo relacionado

Similar a include getopt in this code with the usage doublesort [-d] [-o out.pdf

This code currently works... Run it and get a screen shot of its .docx por
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docxKomlin1
4 visualizações7 slides
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf por
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdfPLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdffoottraders
2 visualizações6 slides
computer notes - Data Structures - 3 por
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3ecomputernotes
5 visualizações46 slides
This code currently works. Run it and get a screen shot of its ou.docx por
 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
5 visualizações10 slides
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf por
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfgalagirishp
3 visualizações4 slides
Lab-2.4 101.pdf por
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf21E135MAHIESHWARJ
6 visualizações11 slides

Similar a include getopt in this code with the usage doublesort [-d] [-o out.pdf(20)

This code currently works... Run it and get a screen shot of its .docx por Komlin1
 This code currently works... Run it and get a screen shot of its .docx This code currently works... Run it and get a screen shot of its .docx
This code currently works... Run it and get a screen shot of its .docx
Komlin14 visualizações
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf por foottraders
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdfPLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf
PLEASE FILL OUT THE TODO lines of code. NEED HELP COMPLETING T.pdf
foottraders2 visualizações
computer notes - Data Structures - 3 por ecomputernotes
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
ecomputernotes5 visualizações
This code currently works. Run it and get a screen shot of its ou.docx por Komlin1
 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
Komlin15 visualizações
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf por galagirishp
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
galagirishp3 visualizações
C++ Homework Help por C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
C++ Homework Help10 visualizações
Implement of c & its coding programming by sarmad baloch por Sarmad Baloch
Implement of c & its coding  programming by sarmad balochImplement of c & its coding  programming by sarmad baloch
Implement of c & its coding programming by sarmad baloch
Sarmad Baloch78 visualizações
Project Description#include #include struct node {.docx por denneymargareta
Project Description#include #include struct node {.docxProject Description#include #include struct node {.docx
Project Description#include #include struct node {.docx
denneymargareta1 visão
write recursive function that calculates and returns the length of a.pdf por arpitcomputronics
write recursive function that calculates and returns the length of a.pdfwrite recursive function that calculates and returns the length of a.pdf
write recursive function that calculates and returns the length of a.pdf
arpitcomputronics3 visualizações
DSA(1).pptx por DaniyalAli81
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli815 visualizações
Consider the following data structure- struct Node { int data- Node -n.docx por kaseya1
Consider the following data structure- struct Node { int data- Node -n.docxConsider the following data structure- struct Node { int data- Node -n.docx
Consider the following data structure- struct Node { int data- Node -n.docx
kaseya12 visualizações
20-13 Programming Project #05A Given the IntNode class- define the Fin.docx por DavidxyNSimpsons
20-13 Programming Project #05A Given the IntNode class- define the Fin.docx20-13 Programming Project #05A Given the IntNode class- define the Fin.docx
20-13 Programming Project #05A Given the IntNode class- define the Fin.docx
DavidxyNSimpsons77 visualizações
How to Write Node.js Module por Fred Chien
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
Fred Chien9.7K visualizações
Write java program using linked list to get integer from user and.docx por ajoy21
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docx
ajoy213 visualizações
COW por 永泉 韩
COWCOW
COW
永泉 韩64 visualizações
#include stdlib.h#include stdio.hstruct node{ int .pdf por alstradecentreerode
#include stdlib.h#include stdio.hstruct node{     int .pdf#include stdlib.h#include stdio.hstruct node{     int .pdf
#include stdlib.h#include stdio.hstruct node{ int .pdf
alstradecentreerode2 visualizações
Data StructuresPlease I need help completing this c++ program..pdf por arkleatheray
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray2 visualizações
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx por acarolyn
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
acarolyn5 visualizações

Mais de aggarwalenterprisesf

Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdf por
Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdfIndirect Methods of Reconstructing Income, Money Laundering and Tran.pdf
Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdfaggarwalenterprisesf
18 visualizações1 slide
it must give every word aloneand Root disables it Stemming is th.pdf por
it must give every word aloneand Root disables it Stemming is th.pdfit must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdfaggarwalenterprisesf
5 visualizações1 slide
it must give every word aloneand Root disables itit must give .pdf por
it must give every word aloneand Root disables itit must give .pdfit must give every word aloneand Root disables itit must give .pdf
it must give every word aloneand Root disables itit must give .pdfaggarwalenterprisesf
2 visualizações1 slide
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdf por
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdfInterprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdf
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdfaggarwalenterprisesf
2 visualizações2 slides
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf por
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfIntroducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfaggarwalenterprisesf
2 visualizações1 slide
Insert the correct words into the blanks in the textThe protein.pdf por
Insert the correct words into the blanks in the textThe protein.pdfInsert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdfaggarwalenterprisesf
2 visualizações1 slide

Mais de aggarwalenterprisesf(20)

Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdf por aggarwalenterprisesf
Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdfIndirect Methods of Reconstructing Income, Money Laundering and Tran.pdf
Indirect Methods of Reconstructing Income, Money Laundering and Tran.pdf
aggarwalenterprisesf18 visualizações
it must give every word aloneand Root disables it Stemming is th.pdf por aggarwalenterprisesf
it must give every word aloneand Root disables it Stemming is th.pdfit must give every word aloneand Root disables it Stemming is th.pdf
it must give every word aloneand Root disables it Stemming is th.pdf
aggarwalenterprisesf5 visualizações
it must give every word aloneand Root disables itit must give .pdf por aggarwalenterprisesf
it must give every word aloneand Root disables itit must give .pdfit must give every word aloneand Root disables itit must give .pdf
it must give every word aloneand Root disables itit must give .pdf
aggarwalenterprisesf2 visualizações
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdf por aggarwalenterprisesf
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdfInterprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdf
Interprete la siguiente declaraci�n de Excel en la celda C2 con resp.pdf
aggarwalenterprisesf2 visualizações
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf por aggarwalenterprisesf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdfIntroducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
Introducci�n al paciente Eva Madison es una ni�a cauc�sica de 5 .pdf
aggarwalenterprisesf2 visualizações
Insert the correct words into the blanks in the textThe protein.pdf por aggarwalenterprisesf
Insert the correct words into the blanks in the textThe protein.pdfInsert the correct words into the blanks in the textThe protein.pdf
Insert the correct words into the blanks in the textThe protein.pdf
aggarwalenterprisesf2 visualizações
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdf por aggarwalenterprisesf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdfIrkanias aggregate Irkanias aggregate expenditures function is sho.pdf
Irkanias aggregate Irkanias aggregate expenditures function is sho.pdf
aggarwalenterprisesf2 visualizações
IntroductionThe introduction should summarise the aims and objecti.pdf por aggarwalenterprisesf
IntroductionThe introduction should summarise the aims and objecti.pdfIntroductionThe introduction should summarise the aims and objecti.pdf
IntroductionThe introduction should summarise the aims and objecti.pdf
aggarwalenterprisesf4 visualizações
Investigue la historia de huracanes en la Costa del Golfo. �En qu�.pdf por aggarwalenterprisesf
Investigue la historia de huracanes en la Costa del Golfo. �En qu�.pdfInvestigue la historia de huracanes en la Costa del Golfo. �En qu�.pdf
Investigue la historia de huracanes en la Costa del Golfo. �En qu�.pdf
aggarwalenterprisesf2 visualizações
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf por aggarwalenterprisesf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdfInvestigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
Investigue Halcones de cola roja usando la enciclopedia en l�nea All.pdf
aggarwalenterprisesf2 visualizações
Invierte una sola cantidad de $17,250 durante 9 a�os al 14 por cient.pdf por aggarwalenterprisesf
Invierte una sola cantidad de $17,250 durante 9 a�os al 14 por cient.pdfInvierte una sola cantidad de $17,250 durante 9 a�os al 14 por cient.pdf
Invierte una sola cantidad de $17,250 durante 9 a�os al 14 por cient.pdf
aggarwalenterprisesf2 visualizações
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf por aggarwalenterprisesf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdfIntroducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
Introducci�nCochinillas En el ejercicio de hoy, utilizaremos el.pdf
aggarwalenterprisesf4 visualizações
Introducci�n El vocabulario, como una de las �reas de conocimient.pdf por aggarwalenterprisesf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdfIntroducci�n El vocabulario, como una de las �reas de conocimient.pdf
Introducci�n El vocabulario, como una de las �reas de conocimient.pdf
aggarwalenterprisesf3 visualizações
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaa.pdf por aggarwalenterprisesf
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaa.pdfInside lab07.fasta, here is the sequence lab07 ttatgtactctaa.pdf
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaa.pdf
aggarwalenterprisesf3 visualizações
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaagg.pdf por aggarwalenterprisesf
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaagg.pdfInside lab07.fasta, here is the sequence lab07 ttatgtactctaagg.pdf
Inside lab07.fasta, here is the sequence lab07 ttatgtactctaagg.pdf
aggarwalenterprisesf3 visualizações
inizi kolaylatrmak i�in cevab a�klamadan soru numarasn ve cevap mekt.pdf por aggarwalenterprisesf
inizi kolaylatrmak i�in cevab a�klamadan soru numarasn ve cevap mekt.pdfinizi kolaylatrmak i�in cevab a�klamadan soru numarasn ve cevap mekt.pdf
inizi kolaylatrmak i�in cevab a�klamadan soru numarasn ve cevap mekt.pdf
aggarwalenterprisesf2 visualizações
In this task you have been given code that asks the user to enter 3 .pdf por aggarwalenterprisesf
In this task you have been given code that asks the user to enter 3 .pdfIn this task you have been given code that asks the user to enter 3 .pdf
In this task you have been given code that asks the user to enter 3 .pdf
aggarwalenterprisesf4 visualizações
Indica si las siguientes son VERDADERAS o FALSAS. Una empresa tu.pdf por aggarwalenterprisesf
Indica si las siguientes son VERDADERAS o FALSAS. Una empresa tu.pdfIndica si las siguientes son VERDADERAS o FALSAS. Una empresa tu.pdf
Indica si las siguientes son VERDADERAS o FALSAS. Una empresa tu.pdf
aggarwalenterprisesf2 visualizações
Indique a qu� cuenta pertenecen estas transacciones desde la perspec.pdf por aggarwalenterprisesf
Indique a qu� cuenta pertenecen estas transacciones desde la perspec.pdfIndique a qu� cuenta pertenecen estas transacciones desde la perspec.pdf
Indique a qu� cuenta pertenecen estas transacciones desde la perspec.pdf
aggarwalenterprisesf2 visualizações
In your own words describe opportunity cost, how it is used in the b.pdf por aggarwalenterprisesf
In your own words describe opportunity cost, how it is used in the b.pdfIn your own words describe opportunity cost, how it is used in the b.pdf
In your own words describe opportunity cost, how it is used in the b.pdf
aggarwalenterprisesf2 visualizações

Último

Psychology KS5 por
Psychology KS5Psychology KS5
Psychology KS5WestHatch
93 visualizações5 slides
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... por
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Ms. Pooja Bhandare
93 visualizações45 slides
Structure and Functions of Cell.pdf por
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdfNithya Murugan
545 visualizações10 slides
The basics - information, data, technology and systems.pdf por
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdfJonathanCovena1
115 visualizações1 slide
11.28.23 Social Capital and Social Exclusion.pptx por
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptxmary850239
298 visualizações25 slides
Psychology KS4 por
Psychology KS4Psychology KS4
Psychology KS4WestHatch
84 visualizações4 slides

Último(20)

Psychology KS5 por WestHatch
Psychology KS5Psychology KS5
Psychology KS5
WestHatch93 visualizações
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant... por Ms. Pooja Bhandare
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Pharmaceutical Inorganic Chemistry Unit IVMiscellaneous compounds Expectorant...
Ms. Pooja Bhandare93 visualizações
Structure and Functions of Cell.pdf por Nithya Murugan
Structure and Functions of Cell.pdfStructure and Functions of Cell.pdf
Structure and Functions of Cell.pdf
Nithya Murugan545 visualizações
The basics - information, data, technology and systems.pdf por JonathanCovena1
The basics - information, data, technology and systems.pdfThe basics - information, data, technology and systems.pdf
The basics - information, data, technology and systems.pdf
JonathanCovena1115 visualizações
11.28.23 Social Capital and Social Exclusion.pptx por mary850239
11.28.23 Social Capital and Social Exclusion.pptx11.28.23 Social Capital and Social Exclusion.pptx
11.28.23 Social Capital and Social Exclusion.pptx
mary850239298 visualizações
Psychology KS4 por WestHatch
Psychology KS4Psychology KS4
Psychology KS4
WestHatch84 visualizações
PLASMA PROTEIN (2).pptx por MEGHANA C
PLASMA PROTEIN (2).pptxPLASMA PROTEIN (2).pptx
PLASMA PROTEIN (2).pptx
MEGHANA C68 visualizações
Create a Structure in VBNet.pptx por Breach_P
Create a Structure in VBNet.pptxCreate a Structure in VBNet.pptx
Create a Structure in VBNet.pptx
Breach_P75 visualizações
Narration lesson plan.docx por TARIQ KHAN
Narration lesson plan.docxNarration lesson plan.docx
Narration lesson plan.docx
TARIQ KHAN112 visualizações
JiscOAWeek_LAIR_slides_October2023.pptx por Jisc
JiscOAWeek_LAIR_slides_October2023.pptxJiscOAWeek_LAIR_slides_October2023.pptx
JiscOAWeek_LAIR_slides_October2023.pptx
Jisc96 visualizações
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf por SukhwinderSingh895865
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdfCWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
CWP_23995_2013_17_11_2023_FINAL_ORDER.pdf
SukhwinderSingh895865527 visualizações
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1} por DR .PALLAVI PATHANIA
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA249 visualizações
Class 10 English notes 23-24.pptx por TARIQ KHAN
Class 10 English notes 23-24.pptxClass 10 English notes 23-24.pptx
Class 10 English notes 23-24.pptx
TARIQ KHAN131 visualizações
Education and Diversity.pptx por DrHafizKosar
Education and Diversity.pptxEducation and Diversity.pptx
Education and Diversity.pptx
DrHafizKosar173 visualizações
ICS3211_lecture 08_2023.pdf por Vanessa Camilleri
ICS3211_lecture 08_2023.pdfICS3211_lecture 08_2023.pdf
ICS3211_lecture 08_2023.pdf
Vanessa Camilleri149 visualizações
Java Simplified: Understanding Programming Basics por Akshaj Vadakkath Joshy
Java Simplified: Understanding Programming BasicsJava Simplified: Understanding Programming Basics
Java Simplified: Understanding Programming Basics
Akshaj Vadakkath Joshy295 visualizações
Use of Probiotics in Aquaculture.pptx por AKSHAY MANDAL
Use of Probiotics in Aquaculture.pptxUse of Probiotics in Aquaculture.pptx
Use of Probiotics in Aquaculture.pptx
AKSHAY MANDAL100 visualizações
Drama KS5 Breakdown por WestHatch
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch79 visualizações
AI Tools for Business and Startups por Svetlin Nakov
AI Tools for Business and StartupsAI Tools for Business and Startups
AI Tools for Business and Startups
Svetlin Nakov107 visualizações

include getopt in this code with the usage doublesort [-d] [-o out.pdf

  • 1. include getopt in this code with the usage % doublesort [-d] [-o output_file_name] input_file_name: #include #include #include #include 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;
  • 2. 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]);
  • 3. 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; }