SlideShare a Scribd company logo
1 of 4
--> Rewrite checkSorted() and replace() using good coding style.
--> Updated the main() function if/as needed.
--> Write comments to briefly explain your improvements.
Written by:
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct stu{
long id;
char name[32];
};
int checkSorted(char password[]);
int replace(struct stu list[], int *length, const struct stu *ptrData, int *location);
int main( )
{
// Test checkSorted()
char myPassword[] = "abcdefg";
char oldPassword[] = "bcdeabc";
printf("%s %dn", myPassword, checkSorted(myPassword));
printf("%s %dnn", oldPassword, checkSorted(oldPassword));
// Test replace()
struct stu list[10] =
{
{88219017, "Ron House"},
{34951406, "John W. Perry"},
{31103628, "Dennis M. Ritchie"}
};
int length = 3;
int status;
int location = 2;
struct stu newData = {11223344, "Brian W. Kernighan"};
for (int i = 0; i < length; i++){
printf("%ld %sn", list[i].id, list[i].name);
}
status = replace(list, &length, &newData, &location);
printf("status: %dn", status);
for (int i = 0; i < length; i++){
printf("%ld %sn", list[i].id, list[i].name);
}
return 0;
}
/*
This function checks if the characters in pasword are sorted in ascending order
Rewrite the following code to:
--> eliminate the call for strlen()
--> replace index k with a pointer
--> make other changes to improve the code
--> write comments to briefly explain your improvements
*/
int checkSorted(char password[])
{
int k;
int sorted = 1;
k = 1;
while (sorted == 1 && k < strlen(password))
{
if (password[k] < password[k - 1])
sorted = 0;
k++;
}
if (sorted == 1)
return 1;
else if (sorted == 0)
return 0;
else return 2;
}
/*
This function replaces the element at a given location in list[]
with data pointed to by its third parameter.
What are the changes that would improve this function?
Make it:
--> simpler
--> shorter
--> easier to read
Write comments to briefly explain your improvements.
*/
int replace(struct stu list[], int *length, const struct stu *ptrData, int *location)
{
if (*location < 0 || *location >= *length){
return 0; // location is out of range
}
list[*location].id = ptrData->id;
strcpy(list[*location].name, ptrData->name);
return 1;
}

More Related Content

Similar to --- Rewrite checkSorted() and replace() using good coding style- --- U.docx

Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! aleks-f
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...GkhanGirgin3
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfaccess2future1
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxDIPESH30
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matchingShakila Mahjabin
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfarjuncollection
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfmalavshah9013
 
Structures in C.pptx
Structures in C.pptxStructures in C.pptx
Structures in C.pptxBoni Yeamin
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdfNitesh Dubey
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateKiev ALT.NET
 

Similar to --- Rewrite checkSorted() and replace() using good coding style- --- U.docx (20)

strings
stringsstrings
strings
 
Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! Look Ma, “update DB to HTML5 using C++”, no hands! 
Look Ma, “update DB to HTML5 using C++”, no hands! 
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
booksoncprogramminglanguage-anintroductiontobeginnersbyarunumrao4-21101016591...
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
c programming
c programmingc programming
c programming
 
C program
C programC program
C program
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 
Complete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdfComplete DB code following the instructions Implement the D.pdf
Complete DB code following the instructions Implement the D.pdf
 
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docxlab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
lab03build.bat@echo offclsset DRIVE_LETTER=1set.docx
 
C++11 - STL Additions
C++11 - STL AdditionsC++11 - STL Additions
C++11 - STL Additions
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
array, function, pointer, pattern matching
array, function, pointer, pattern matchingarray, function, pointer, pattern matching
array, function, pointer, pattern matching
 
So I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdfSo I already have most of the code and now I have to1. create an .pdf
So I already have most of the code and now I have to1. create an .pdf
 
Create a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdfCreate a JAVA program that performs file IO and database interaction.pdf
Create a JAVA program that performs file IO and database interaction.pdf
 
week-6x
week-6xweek-6x
week-6x
 
Structures in C.pptx
Structures in C.pptxStructures in C.pptx
Structures in C.pptx
 
Compiler design.pdf
Compiler design.pdfCompiler design.pdf
Compiler design.pdf
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
Strings in C
Strings in CStrings in C
Strings in C
 

More from hoggardbennie

( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx
( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx
( 1 point) Generate two random numbers between 0 and 1 and take X to b.docxhoggardbennie
 
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docxhoggardbennie
 
1 52 - 14 () - 11 If the interest rate is 10- per year compounde.docx
1  52 - 14  () -    11  If the interest rate is 10- per year compounde.docx1  52 - 14  () -    11  If the interest rate is 10- per year compounde.docx
1 52 - 14 () - 11 If the interest rate is 10- per year compounde.docxhoggardbennie
 
-Mosquitoes appear to use odors to help them distinguish what is nearb.docx
-Mosquitoes appear to use odors to help them distinguish what is nearb.docx-Mosquitoes appear to use odors to help them distinguish what is nearb.docx
-Mosquitoes appear to use odors to help them distinguish what is nearb.docxhoggardbennie
 
-template- (I assume that all of the text below goes in the body of th.docx
-template- (I assume that all of the text below goes in the body of th.docx-template- (I assume that all of the text below goes in the body of th.docx
-template- (I assume that all of the text below goes in the body of th.docxhoggardbennie
 
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docxhoggardbennie
 
-f- Derive- A(BC).docx
-f- Derive- A(BC).docx-f- Derive- A(BC).docx
-f- Derive- A(BC).docxhoggardbennie
 
-Emotions are now often seen as central to certain organisational role.docx
-Emotions are now often seen as central to certain organisational role.docx-Emotions are now often seen as central to certain organisational role.docx
-Emotions are now often seen as central to certain organisational role.docxhoggardbennie
 
-- C Program How might I modify this code to handle any number of comm.docx
-- C Program How might I modify this code to handle any number of comm.docx-- C Program How might I modify this code to handle any number of comm.docx
-- C Program How might I modify this code to handle any number of comm.docxhoggardbennie
 
- What is osmosis and the three types of osmosis- Explain- - Which typ.docx
- What is osmosis and the three types of osmosis- Explain- - Which typ.docx- What is osmosis and the three types of osmosis- Explain- - Which typ.docx
- What is osmosis and the three types of osmosis- Explain- - Which typ.docxhoggardbennie
 
- Toss a coin three times- Let X- Heads - Tails- Find the distributio.docx
- Toss a coin three times- Let X- Heads -  Tails- Find the distributio.docx- Toss a coin three times- Let X- Heads -  Tails- Find the distributio.docx
- Toss a coin three times- Let X- Heads - Tails- Find the distributio.docxhoggardbennie
 
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docxhoggardbennie
 
- Let X be a random variable has a normal distribution with -30 and -1.docx
- Let X be a random variable has a normal distribution with -30 and -1.docx- Let X be a random variable has a normal distribution with -30 and -1.docx
- Let X be a random variable has a normal distribution with -30 and -1.docxhoggardbennie
 
- A patient with emphysema is admitted to your unit- The patient is s.docx
-  A patient with emphysema is admitted to your unit- The patient is s.docx-  A patient with emphysema is admitted to your unit- The patient is s.docx
- A patient with emphysema is admitted to your unit- The patient is s.docxhoggardbennie
 
(X-Y)-(1-1)limxyxy.docx
(X-Y)-(1-1)limxyxy.docx(X-Y)-(1-1)limxyxy.docx
(X-Y)-(1-1)limxyxy.docxhoggardbennie
 
(shady) conditions will most likely have a-fewer chloroplasts than sun.docx
(shady) conditions will most likely have a-fewer chloroplasts than sun.docx(shady) conditions will most likely have a-fewer chloroplasts than sun.docx
(shady) conditions will most likely have a-fewer chloroplasts than sun.docxhoggardbennie
 
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docxhoggardbennie
 
(a) Are these data categorical or quantitative- categorical quantitati.docx
(a) Are these data categorical or quantitative- categorical quantitati.docx(a) Are these data categorical or quantitative- categorical quantitati.docx
(a) Are these data categorical or quantitative- categorical quantitati.docxhoggardbennie
 
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docxhoggardbennie
 

More from hoggardbennie (20)

( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx
( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx
( 1 point) Generate two random numbers between 0 and 1 and take X to b.docx
 
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx
(4) Ni is and D indebendent everts- Yes- bocine T(p)-F(0M) No- beause.docx
 
1 52 - 14 () - 11 If the interest rate is 10- per year compounde.docx
1  52 - 14  () -    11  If the interest rate is 10- per year compounde.docx1  52 - 14  () -    11  If the interest rate is 10- per year compounde.docx
1 52 - 14 () - 11 If the interest rate is 10- per year compounde.docx
 
-Mosquitoes appear to use odors to help them distinguish what is nearb.docx
-Mosquitoes appear to use odors to help them distinguish what is nearb.docx-Mosquitoes appear to use odors to help them distinguish what is nearb.docx
-Mosquitoes appear to use odors to help them distinguish what is nearb.docx
 
-template- (I assume that all of the text below goes in the body of th.docx
-template- (I assume that all of the text below goes in the body of th.docx-template- (I assume that all of the text below goes in the body of th.docx
-template- (I assume that all of the text below goes in the body of th.docx
 
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx
--- - Class to demonstrate Generic Pair class -author john1819 - -- pu.docx
 
-f- Derive- A(BC).docx
-f- Derive- A(BC).docx-f- Derive- A(BC).docx
-f- Derive- A(BC).docx
 
-Emotions are now often seen as central to certain organisational role.docx
-Emotions are now often seen as central to certain organisational role.docx-Emotions are now often seen as central to certain organisational role.docx
-Emotions are now often seen as central to certain organisational role.docx
 
-- C Program How might I modify this code to handle any number of comm.docx
-- C Program How might I modify this code to handle any number of comm.docx-- C Program How might I modify this code to handle any number of comm.docx
-- C Program How might I modify this code to handle any number of comm.docx
 
- What is osmosis and the three types of osmosis- Explain- - Which typ.docx
- What is osmosis and the three types of osmosis- Explain- - Which typ.docx- What is osmosis and the three types of osmosis- Explain- - Which typ.docx
- What is osmosis and the three types of osmosis- Explain- - Which typ.docx
 
- Toss a coin three times- Let X- Heads - Tails- Find the distributio.docx
- Toss a coin three times- Let X- Heads -  Tails- Find the distributio.docx- Toss a coin three times- Let X- Heads -  Tails- Find the distributio.docx
- Toss a coin three times- Let X- Heads - Tails- Find the distributio.docx
 
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx
(1) In the tubular flowers of foxgloves- wild-type coloration is red-.docx
 
- Let X be a random variable has a normal distribution with -30 and -1.docx
- Let X be a random variable has a normal distribution with -30 and -1.docx- Let X be a random variable has a normal distribution with -30 and -1.docx
- Let X be a random variable has a normal distribution with -30 and -1.docx
 
- A patient with emphysema is admitted to your unit- The patient is s.docx
-  A patient with emphysema is admitted to your unit- The patient is s.docx-  A patient with emphysema is admitted to your unit- The patient is s.docx
- A patient with emphysema is admitted to your unit- The patient is s.docx
 
(X-Y)-(1-1)limxyxy.docx
(X-Y)-(1-1)limxyxy.docx(X-Y)-(1-1)limxyxy.docx
(X-Y)-(1-1)limxyxy.docx
 
(shady) conditions will most likely have a-fewer chloroplasts than sun.docx
(shady) conditions will most likely have a-fewer chloroplasts than sun.docx(shady) conditions will most likely have a-fewer chloroplasts than sun.docx
(shady) conditions will most likely have a-fewer chloroplasts than sun.docx
 
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx
(i) Werck the icon to vere the trpssictons) More info Requirements 1-.docx
 
(ABC)B.docx
(ABC)B.docx(ABC)B.docx
(ABC)B.docx
 
(a) Are these data categorical or quantitative- categorical quantitati.docx
(a) Are these data categorical or quantitative- categorical quantitati.docx(a) Are these data categorical or quantitative- categorical quantitati.docx
(a) Are these data categorical or quantitative- categorical quantitati.docx
 
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx
(a) The vector xRN has L different entries- For example- L-4 for x--3-.docx
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

--- Rewrite checkSorted() and replace() using good coding style- --- U.docx

  • 1. --> Rewrite checkSorted() and replace() using good coding style. --> Updated the main() function if/as needed. --> Write comments to briefly explain your improvements. Written by: */ #include <stdio.h> #include <string.h> #include <ctype.h> struct stu{ long id; char name[32]; }; int checkSorted(char password[]); int replace(struct stu list[], int *length, const struct stu *ptrData, int *location); int main( ) { // Test checkSorted() char myPassword[] = "abcdefg"; char oldPassword[] = "bcdeabc"; printf("%s %dn", myPassword, checkSorted(myPassword)); printf("%s %dnn", oldPassword, checkSorted(oldPassword)); // Test replace() struct stu list[10] =
  • 2. { {88219017, "Ron House"}, {34951406, "John W. Perry"}, {31103628, "Dennis M. Ritchie"} }; int length = 3; int status; int location = 2; struct stu newData = {11223344, "Brian W. Kernighan"}; for (int i = 0; i < length; i++){ printf("%ld %sn", list[i].id, list[i].name); } status = replace(list, &length, &newData, &location); printf("status: %dn", status); for (int i = 0; i < length; i++){ printf("%ld %sn", list[i].id, list[i].name); } return 0; } /* This function checks if the characters in pasword are sorted in ascending order Rewrite the following code to: --> eliminate the call for strlen()
  • 3. --> replace index k with a pointer --> make other changes to improve the code --> write comments to briefly explain your improvements */ int checkSorted(char password[]) { int k; int sorted = 1; k = 1; while (sorted == 1 && k < strlen(password)) { if (password[k] < password[k - 1]) sorted = 0; k++; } if (sorted == 1) return 1; else if (sorted == 0) return 0; else return 2; } /* This function replaces the element at a given location in list[]
  • 4. with data pointed to by its third parameter. What are the changes that would improve this function? Make it: --> simpler --> shorter --> easier to read Write comments to briefly explain your improvements. */ int replace(struct stu list[], int *length, const struct stu *ptrData, int *location) { if (*location < 0 || *location >= *length){ return 0; // location is out of range } list[*location].id = ptrData->id; strcpy(list[*location].name, ptrData->name); return 1; }