1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
LiRa [457]
3 years ago
13

(1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted

: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two strings. (2 pts) Ex: Enter input string: Jill Allen Error: No comma in string Enter input string: Jill, Allen (3) Extract the two words from the input string and remove any spaces. Store the strings in two separate variables and output the strings. (2 pts) Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen (4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit. (2 pts) Ex: Enter input string: Jill, Allen First word: Jill Second word: Allen Enter input string: Golden , Monkey First word: Golden Second word: Monkey Enter input string: Washington,DC First word: Washington Second word: DC Enter input string: q

Computers and Technology
1 answer:
denis-greek [22]3 years ago
4 0

Answer:

Check the explanation

Explanation:

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#define MAX_LIMIT 50

int checkComma(char *input)

{

int flag = 0;

for(int i = 0; i < strlen(input); i++)

{

if(input[i] == ',')

{

flag = 1;

break;

}

}

return flag;

}

int main(void)

{

char input[MAX_LIMIT];

char *words[2];

char delim[] = ", ";

printf("\n");

do

{

printf("Enter input string: ");

fgets(input, MAX_LIMIT, stdin);

size_t ln = strlen(input) - 1;

if (*input && input[ln] == '\n')

input[ln] = '\0';

if(strcmp(input, "q") == 0)

{

printf("Thank you...Exiting\n\n");

exit(1);

}

else

{

if(checkComma(input) == 0)

{

printf("No comma in string.\n\n");

}

else

{

char *ptr = strtok(input, delim);

int count = 0;

while(ptr != NULL)

{

words[count++] = ptr;

ptr = strtok(NULL, delim);

}

printf("First word: %s\n", words[0]);

printf("Second word: %s\n\n", words[1]);

}

}

}while(strcmp(input, "q") != 0);

return 0;

}

Kindly check the attached image below for the output.

You might be interested in
Compare and contrast hardware and software.
lesya692 [45]
Hardware:
-physical parts of a computer that cause processing of data
-can be connected (physically) & can touch
- Hardware wares out during/over time
-Hardware failure is random
Software:
-A set of construction that tells a computer exactly what to do
-software is logical in nature
- dose not have an increasing failure rate

Similarities
- Behavior; Users interact with the products in various ways

- Products produce outputs and given inputs

-they have functional (user facing) and non functional (non user facing) requirements

-They are both complex (any representation of product specifications lead to a main structure)


Differences
- Software is easier to change then hardware

- Software testing is done by specialized quality assurance (QA) engineers, while hardware is done by engineers who are creating the product

-Hardware must be designed and tested to work over a range of time and environmental conditions, which is not the case for software

- Hardware designs are constrained by the need to incorporate standard parts

(Hope this helps?)
7 0
2 years ago
Read 2 more answers
Patronage of most Medieval musicians was supplied by the
Arturiano [62]

Answer:

wrong^^its church

Explanation:

3 0
3 years ago
to move from the second cell in the table in the accompanying figure back to the previous cell, press the ____ key(s)
Serhud [2]
I believe the answer is Shift + Tab
8 0
3 years ago
what font size should generally be used for the slide title to ensure that it is set off from the content
polet [3.4K]
I would say that you should use 32 pt font
4 0
3 years ago
Given a positive real number, print its fractional part.
givi [52]
<span>The modf() function will do this for you:

double x, y, d;
x = -14.876;
y = modf(x, &d);
printf("Fractional part = %lf\n", y);

</span>
8 0
3 years ago
Other questions:
  • Nick is a food blogger. He first writes his draft on an electronic document, checks and corrects mistakes, and pastes the conten
    9·2 answers
  • Why is timbre an important musical element?
    7·2 answers
  • Search engines enable you to
    13·2 answers
  • Which is a benefit of peer-to-peer networking?
    10·1 answer
  • A new employee has reported that print jobs are printing as garbled text. Which of the following is MOST likely the reason for t
    8·1 answer
  • Data types influence the following in the workflow: (Select all that apply)a. the color choices and layout decisions around comp
    15·2 answers
  • All of the following are aspects of the search process except?
    6·2 answers
  • Lucy has to move data from column A to column N in a worksheet. Which keys should she select to move data in the same worksheet?
    9·2 answers
  • Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the
    6·1 answer
  • 5. Give one word answers:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!