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
Estoy empezando a usar una pagina llamada source filmmaker, no se que apreté y quiero el menú de nuevo (en donde se ponen los mo
yuradex [85]

Answer:

hay un n t s en la esquina superior derecha, debe presionar eso y debe llevarlo al menú si eso no funciona, entonces tengo una idea de qué hacer

Explanation:

7 0
3 years ago
Calculate the number of telephone
olchik [2.2K]

Answer:

yho

Explanation:

hayi no ntwana.... lala boy

6 0
3 years ago
Technician A says that the excessive length of a heater hose is intended to protect the heater core from undue stress. Technicia
hammer [34]
It is both true that <span>Technician A says that the excessive length of a heater hose is intended to protect the heater core from undue stress. Technician B says that excessive wear adds to the length of a heater hose, and a replacement heater hose should be roughly three to four inches shorter than its predecessor.  So the asnwer is letter B.</span>
6 0
3 years ago
When might an lcd monitor experience distorted geometry?
horsena [70]

The time when an LCD monitor is experiencing distorted geometry is when there is a presence of the screen into having a display that is not set on the resolution that is supposed to be in native, this is indicative that it is experiencing distorted geometry.

7 0
3 years ago
When the degree of color contrast between items is low, the content is easier to see and read. True or False
Alexus [3.1K]

the answer is false

hope that helps

3 0
3 years ago
Other questions:
  • Molly wants to make some cells in her balance spreadsheet different colors so that she can more quickly find important data. Wha
    13·2 answers
  • What natural resources fueled industrialization in the united states?
    14·1 answer
  • You have just finished writing a lengthy research paper and you are ready for formatting. You insert your paragraph headings and
    15·1 answer
  • What does Putting a word in quotation marks on your search bar do on google?
    12·1 answer
  • Three common risk factors for young drivers and how you plan to minimize these factors.
    13·1 answer
  • Explain what led to the invention of lasers
    7·1 answer
  • .... . .-.. .-.. --- .-.-.-<br><br><br> TRANSLATE THAT.
    10·1 answer
  • 1. Write a 400-500 word research report about Burke High School.
    6·1 answer
  • Which computer peripheral is used when you would like to use a DVD or CD?
    12·2 answers
  • 45 points!
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!