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
I don't understand how to write code for this in Java using nested for loops only. The official question is: write a program tha
Bingel [31]

Answer:

public class Triangle

{

public static void main( String[] args )

{

show( 5 );

}

public static void show( int n )

{

int i,j,k;

for (i = 0; i < n - 1; i++ )

{

for (j = 0; j < i; j++ )

{

System.out.print( " " );

}

for (k = n - i; k > 0; k-- )

{

System.out.print( "* " );

}

System.out.println();

}

for (i = 0; i < n; i++ )

{

for (j = n - i; j > 1; j-- )

{

System.out.print( " " );

}

for (k = 0; k < i + 1; k++ )

{

System.out.print( "* " );

}

System.out.println();

}

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

Answer:

yho

Explanation:

hayi no ntwana.... lala boy

6 0
2 years ago
Given the number of rows and the number of columns, write nested loops to print a rectangle. (PYTHON)
Allushta [10]

Answer:

Explanation:

Please see the attached picture for help.

6 0
3 years ago
Read 2 more answers
Free up disk space by doing____?​
8090 [49]

Answer:

Deleting files and etc on your computer.

6 0
3 years ago
Read 2 more answers
To turn off the AutoCorrect features, navigate to the AutoCorrect menu and deselect the box labeled_____.
barxatty [35]
Option A-Show AutoCorrect buttons, then you have the options to hide the autocorrect or to turn it on/off
4 0
3 years ago
Read 2 more answers
Other questions:
  • How do u get rid of this (the grey box)
    6·2 answers
  • Any program that allows the user to select an item from a menu should ________ the user's selection.
    7·1 answer
  • What are the features of Cobol language that make it suitable for programming business applications.
    6·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • In news writing, which is bigger , a topic or a angle
    10·1 answer
  • Can maybe someone play with me on Over-watch on the Xbox?
    8·1 answer
  • Need answer ASAP.
    8·1 answer
  • Notes on secondary memory​
    7·1 answer
  • A network of computers that provides access to information on the web.
    15·2 answers
  • Which type of network allows backups and network security to be centrally located?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!