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
Social engineering attacks can be carried out:______.
Alik [6]
The answer most likely B NOT SURE )
3 0
3 years ago
If you weigh 100 pounds, and your 150 pound big sister is sitting 15 feet from the fulcrum of a seesaw, how far from the fulcrum
Dahasolnce [82]

Answer:

22.5

Explanation:

My weight = 100 pounds

Sister's weight = 150

Distance from fulcrum = 15 ft

Distance has an inverse proportion with weight

Distance = k/w

Where k is a constant

K = distance x weight

K = 100 x distance

150 x 15 = 100 distance

2250 = 100 distance

Divide through by 100 to get distance

2250/100 = distance

Distance = 22.5

5 0
3 years ago
T.J. wants to send a friend a file with a funny dancing cat. Which file format should T.J. use?
masha68 [24]

Answer:

If it is a Gif, then T.J. should, obviously, use the GIF format, but I think the answer you're looking for is MP3, since that is generally (at least for me) what videos are sent as!

Hope this helps(:

Explanation:

7 0
3 years ago
Read 2 more answers
THE FOLLOWING IS WRITTEN IN C:
nekit [7.7K]

Answer:

it is b

Explanation:

8 0
3 years ago
How to get free robux <br> cómo conseguir robux gratis<br> come ottenere robux <br> 無料のrobuxを入手する方法
victus00 [196]

Answer:

uhhhhh

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • There is no reason to study the works of famous photographers because they will make you less creative.
    5·2 answers
  • Suppose we have two String objects and treat the characters in each string from beginning to end in the following way: With one
    14·1 answer
  • For which type of long-distance call do you need to tell the operator the name of the person to whom you wish to speak?
    10·1 answer
  • Josephine is in the process of creating ads within her Standard Display campaign. She finds that there are two main ad formats t
    5·1 answer
  • Help me decide this hurry
    12·1 answer
  • In this class, it is very common for your computer screen to look like this. What is this?​
    5·1 answer
  • CS160 Computer Science I In class Lab 10
    15·1 answer
  • The amount of data that can be stored on a disk depends in part on_____.
    13·1 answer
  • Who invented Computer? Answer Differently​
    13·2 answers
  • A construction-based client would like to develop an application that can analyze an image of machinery and overlay information
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!