SlideShare a Scribd company logo
1 of 5
Download to read offline
Question is in the code comments.
C program not C++
No global variables
#include
#include
#include
#include
/* Prompts the user with the message parameter.
Use fgets() to get input from user from stdin (using a separate input buffer defined in the
function).
Converts the input from the user to an integer using atoi() or atol().
If there is an error on conversion, prompts the user that there is an error and then prompts
them to try again.
Continues the loop until the user succesfully inputs an integer. Returns the integer. */
int getInt(char message[]);
/* Prompts the user with the message parameter.
Use fgets() to get input from the user from stdin (using a separate input buffer defined in the
function).
Removes the hard return from the input.
Ensures that the string provided is no longer than the length parameter.
If the string is too long, prompts the user about the error and then prompts the user to try
again.
Continues the loop until the user is succesful.
Copies the user input into the target parameter once it is correct length. */
void getString(char message[], char target[], int length);
/* Prompts the user with the message parameter.
Use fgets() to get input from user from stdin (using a separate input buffer defined in the
function).
Converts the input from the user to a double using atof.
If there is an error on conversion, prompts the user that there is an error and then prompts
them to try again.
Continues the loop until the user succesfully inputs a double. Returns the double. */
double getDouble(char message[]);
/* Prompts the user with the message parameter.
Compares the input from the user to an alphabet character using isalpha().
If there is an error on comparison, prompts the user that there is an error and then prompts
them to try again.
Continues the loop until the user succesfully inputs an alphabet character. Returns the alphabet
character. */
char getAlpha(char message[]);
int main(int argc, char *argv[]) {
return 0;
}
int getInt(char message[]) {
}
void getString(char message[], char target[], int length) {
}
double getDouble(char message[]) {
}
char getAlpha(char message[]) {
}
Solution
Here is the code for you:
#include
#include
#include
#include
/* Prompts the user with the message parameter.
Use fgets() to get input from user from stdin (using a separate input buffer defined in the
function).
Converts the input from the user to an integer using atoi() or atol().
If there is an error on conversion, prompts the user that there is an error and then prompts them
to try again.
Continues the loop until the user succesfully inputs an integer. Returns the integer. */
int getInt(char message[]);
/* Prompts the user with the message parameter.
Use fgets() to get input from the user from stdin (using a separate input buffer defined in the
function).
Removes the hard return from the input.
Ensures that the string provided is no longer than the length parameter.
If the string is too long, prompts the user about the error and then prompts the user to try again.
Continues the loop until the user is succesful.
Copies the user input into the target parameter once it is correct length. */
void getString(char message[], char target[], int length);
/* Prompts the user with the message parameter.
Use fgets() to get input from user from stdin (using a separate input buffer defined in the
function).
Converts the input from the user to a double using atof.
If there is an error on conversion, prompts the user that there is an error and then prompts them
to try again.
Continues the loop until the user succesfully inputs a double. Returns the double. */
double getDouble(char message[]);
/* Prompts the user with the message parameter.
Compares the input from the user to an alphabet character using isalpha().
If there is an error on comparison, prompts the user that there is an error and then prompts them
to try again.
Continues the loop until the user succesfully inputs an alphabet character. Returns the alphabet
character. */
char getAlpha(char message[]);
int main(int argc, char *argv[]) {
return 0;
}
int getInt(char message[])
{
printf("%s", message);
char input[5];
int num;
fgets(input, 5, stdin);
num = atoi(input);
while(num == 0)
{
printf("Error: Invalid input. ");
printf("%s", message);
fgets(input, 5, stdin);
num = atoi(input);
}
return num;
}
void getString(char message[], char target[], int length)
{
printf("%s", message);
fgets(target, 5, stdin);
while(strlen(target) > length)
{
printf("Error: Invalid input. ");
printf("%s", message);
fgets(target, 5, stdin);
}
}
double getDouble(char message[])
{
printf("%s", message);
char input[5];
double num;
fgets(input, 5, stdin);
num = atof(input);
while(num == 0)
{
printf("Error: Invalid input. ");
printf("%s", message);
fgets(input, 5, stdin);
num = atof(input);
}
return num;
}
char getAlpha(char message[])
{
printf("%s", message);
char ch;
ch = fgetc(stdin);
while(!isalpha(ch))
{
printf("Error: Invalid input. ");
printf("%s", message);
ch = fgetc(stdin);
}
return ch;
}

More Related Content

Similar to Question is in the code comments.C program not C++No global vari.pdf

C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
HCMUTE
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
newfaransportsfitnes
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
stopgolook
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
amrit47
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
Rakesh Madugula
 
operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
 operating system Ubunut,Linux,Mac filename messageService.cpp.pdf operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
annethafashion
 

Similar to Question is in the code comments.C program not C++No global vari.pdf (20)

C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)Composing an App with Free Monads (using Cats)
Composing an App with Free Monads (using Cats)
 
C++_notes.pdf
C++_notes.pdfC++_notes.pdf
C++_notes.pdf
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Object Oriented Programming with C++
Object Oriented Programming with C++Object Oriented Programming with C++
Object Oriented Programming with C++
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
in c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdfin c languageTo determine the maximum string length, we need to .pdf
in c languageTo determine the maximum string length, we need to .pdf
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
Wien15 java8
Wien15 java8Wien15 java8
Wien15 java8
 
C function
C functionC function
C function
 
operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
 operating system Ubunut,Linux,Mac filename messageService.cpp.pdf operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
operating system Ubunut,Linux,Mac filename messageService.cpp.pdf
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
Bc0037
Bc0037Bc0037
Bc0037
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

More from aroramobiles1

Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdf
aroramobiles1
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdf
aroramobiles1
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdf
aroramobiles1
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
aroramobiles1
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdf
aroramobiles1
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdf
aroramobiles1
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf
aroramobiles1
 

More from aroramobiles1 (20)

Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdf
 
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
 
ood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdfood evening people. Ive been working on this code that sends a bur.pdf
ood evening people. Ive been working on this code that sends a bur.pdf
 
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
Multiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdfMultiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdf
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
 
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfMitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdf
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfKim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdf
 
HISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfHISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdf
 
Explain what #include does in a source codeSolution Th.pdf
Explain what #include  does in a source codeSolution Th.pdfExplain what #include  does in a source codeSolution Th.pdf
Explain what #include does in a source codeSolution Th.pdf
 
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfdNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdf
 
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfDefine the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
 
Describe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfDescribe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdf
 
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfChapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf
 
You have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfYou have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdf
 
Write a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfWrite a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdf
 

Recently uploaded

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
KarakKing
 

Recently uploaded (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
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
 
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
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
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Ữ Â...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
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.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
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
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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)
 

Question is in the code comments.C program not C++No global vari.pdf

  • 1. Question is in the code comments. C program not C++ No global variables #include #include #include #include /* Prompts the user with the message parameter. Use fgets() to get input from user from stdin (using a separate input buffer defined in the function). Converts the input from the user to an integer using atoi() or atol(). If there is an error on conversion, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs an integer. Returns the integer. */ int getInt(char message[]); /* Prompts the user with the message parameter. Use fgets() to get input from the user from stdin (using a separate input buffer defined in the function). Removes the hard return from the input. Ensures that the string provided is no longer than the length parameter. If the string is too long, prompts the user about the error and then prompts the user to try again. Continues the loop until the user is succesful. Copies the user input into the target parameter once it is correct length. */ void getString(char message[], char target[], int length); /* Prompts the user with the message parameter. Use fgets() to get input from user from stdin (using a separate input buffer defined in the function). Converts the input from the user to a double using atof. If there is an error on conversion, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs a double. Returns the double. */ double getDouble(char message[]); /* Prompts the user with the message parameter. Compares the input from the user to an alphabet character using isalpha().
  • 2. If there is an error on comparison, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs an alphabet character. Returns the alphabet character. */ char getAlpha(char message[]); int main(int argc, char *argv[]) { return 0; } int getInt(char message[]) { } void getString(char message[], char target[], int length) { } double getDouble(char message[]) { } char getAlpha(char message[]) { } Solution Here is the code for you: #include #include #include #include /* Prompts the user with the message parameter. Use fgets() to get input from user from stdin (using a separate input buffer defined in the function). Converts the input from the user to an integer using atoi() or atol(). If there is an error on conversion, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs an integer. Returns the integer. */ int getInt(char message[]); /* Prompts the user with the message parameter. Use fgets() to get input from the user from stdin (using a separate input buffer defined in the
  • 3. function). Removes the hard return from the input. Ensures that the string provided is no longer than the length parameter. If the string is too long, prompts the user about the error and then prompts the user to try again. Continues the loop until the user is succesful. Copies the user input into the target parameter once it is correct length. */ void getString(char message[], char target[], int length); /* Prompts the user with the message parameter. Use fgets() to get input from user from stdin (using a separate input buffer defined in the function). Converts the input from the user to a double using atof. If there is an error on conversion, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs a double. Returns the double. */ double getDouble(char message[]); /* Prompts the user with the message parameter. Compares the input from the user to an alphabet character using isalpha(). If there is an error on comparison, prompts the user that there is an error and then prompts them to try again. Continues the loop until the user succesfully inputs an alphabet character. Returns the alphabet character. */ char getAlpha(char message[]); int main(int argc, char *argv[]) { return 0; } int getInt(char message[]) { printf("%s", message); char input[5]; int num; fgets(input, 5, stdin); num = atoi(input); while(num == 0) { printf("Error: Invalid input. "); printf("%s", message);
  • 4. fgets(input, 5, stdin); num = atoi(input); } return num; } void getString(char message[], char target[], int length) { printf("%s", message); fgets(target, 5, stdin); while(strlen(target) > length) { printf("Error: Invalid input. "); printf("%s", message); fgets(target, 5, stdin); } } double getDouble(char message[]) { printf("%s", message); char input[5]; double num; fgets(input, 5, stdin); num = atof(input); while(num == 0) { printf("Error: Invalid input. "); printf("%s", message); fgets(input, 5, stdin); num = atof(input); } return num; } char getAlpha(char message[]) { printf("%s", message); char ch;
  • 5. ch = fgetc(stdin); while(!isalpha(ch)) { printf("Error: Invalid input. "); printf("%s", message); ch = fgetc(stdin); } return ch; }