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
In the electric series, which one of the following materials is the most negatively charged? A. Silk B. Sealing wax C. Teflon D.
Snowcat [4.5K]
C) Teflon (:


Good luck!
7 0
3 years ago
Read 2 more answers
Which one of these is the most commonly used hardware interface for attaching peripherals to a microcomputer?
Tanzania [10]
Hey there!

The most commonly used hardware interface for attaching peripherals to a microcomputer is the universal series bus, or USB, port. Many computers have at least 2 to 4 USB ports that allow for multiple devices to be plugged in at once. In terms of wired devices as opposed to wireless, this is the main way that a mouse, a keyboard, a smartphone (for charging and syncing information), and many other devices are connected to computers. 

Hope this helped you out! :-)
4 0
2 years ago
Predict how digital video will be viewed in the future. Step into the year 2028. How are people viewing digital video? Or have w
frutty [35]
<span>Google Glass was interesting; a personal screen overlaid onto the real world, with 'augmented reality' ideas. The Nintendo 3DS was the first 'no glasses' portable 3D system.

So I predict Google 3D Glasses with built in Dolby 9.1 sound emulation. </span>
6 0
3 years ago
Read 2 more answers
Write a function called getChar that has no function inputs, but takes in two character inputs from the user (in1 and in2) and o
bearhunter [10]

Answer:

def getChar():

   while True:

       in1 = input('Enter first char: ')

       try:

           if len(in1) != 1:

               raise

           else:

               in2 = input('Enter second char: ')

               if len(in2) != 1:

                   raise

               else:

                   break

       except:

           print('Enter just one character')

   return in1, in2

def chars2string(in1,in2):

   print(in1*5 + in2*5)

def main():

   ls = getChar()

   in1 = ls[0]

   in2 = ls[1]

   chars2string(in1, in2)

if __name__ == '__main__':

   main()

Explanation:

The programming language used is python 3.

The script first defines a function getChar and makes use of a while loop in combination with try and except blocks and IF statements, the code ensures that both inputs that are entered by the user after the prompt are 1 in length. i.e. Just one character. This function returns the two characters that were entered.

The second function that is defined is chars2string this function takes two arguments, It repeats each argument five times and returns a joined string.

Finally, the main function is defined and it calls the getChar function  first, the values that are returned by this function is assigned to two variables, that is then passed on to the chars2string function. The main function is called and the Joined string is printed to the screen.

3 0
3 years ago
. is the language that Web pages are written in?(PHP,XML,HTML,Javascript)
dalvyx [7]

Answer:

<em>HTML</em><em>(</em><em>hypertext</em><em> </em><em>markup</em><em> </em><em>language</em><em>)</em><em> </em>is the language that Web Pages are written in.

4 0
3 years ago
Read 2 more answers
Other questions:
  • The section called Breaking Substitution Ciphers (p. 166) describes a "random substitution cipher," in which each letter of the
    11·1 answer
  • How does the mantle interact with the tectonic plates at a convergent boundary?
    14·2 answers
  • Megan has written the following rough draft for her assignment. Choose the correct way to complete each sentence. Sarah is creat
    13·1 answer
  • For the questions below, consider a class called ChessPiece. This class has two instance data, String type and int player. The v
    13·1 answer
  • Identify the correct sequence of steps to change the font from Verdana to Arial.
    10·1 answer
  • Using a conversation voice is part of:
    9·1 answer
  • Help me pls!!! last question
    9·1 answer
  • Why use LinkedIn automation for LinkedIn?
    10·1 answer
  • A monitor is an output device. Which of the following is not a type of monitor? *
    11·1 answer
  • Which backup requires a small amount of space and is considered to have an involved restoration process?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!