Write a C Program with a main() function that declares the arrays and loops unti
ID: 3770905 • Letter: W
Question
Write a C Program with a main() function that declares the arrays and loops until the user answers Y to the question “do you want to quit?”
main
declare two (2) char arrays that can hold 80 characters each. ca1 and ca2
do
send ca1 to getString with prompt “enter string 1”
send ca2 to getString with prompt “enter string 2”
send ca1 and ca2 to doStrings
printf prompt “Do you want to Quit?”
read answer into one of the arrays
while (answer != “Y” )
end main
void getString( two parameters )
1. character array to fill
2. character array with prompt
print prompt read what user types into 1. array to fill
end getString
Explanation / Answer
What do you wan to do in the doStrings() function. You didn't specified that. Anyways, I just tried printing both the arrays there. If you need any further refinements, just get back to me.
#include <stdio.h>
#include <string.h>
void getString(char input[], char prompt[])
{
printf("%s: ", prompt);
scanf("%s", input);
}
void doStrings(char input1[], char input2[])
{
printf("%s %s ", input1, input2);
}
int main()
{
char ca1[80], ca2[80];
do
{
getString(ca1, "Enter string 1");
getString(ca2, "Enter string 2");
doStrings(ca1, ca2);
printf("Do you want to Quit? ");
scanf("%s",ca1);
}while(strcmp("Y", ca1));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.