
Question is expanding on previous written code bellow(program written in C).
(4) Using a loop, extend the program to handle multiple lines of input. Continue until the user enters q to quit.
Ex:
Current program to expanded on:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_LIMIT 50
//Function definition
int Commacheck(char *input)
{
int flag = 0;
for(int i = 0; i < strlen(input); i++)
{
//if comma is present in the input entered by user, update the fag to 1.
if(input[i] == ',')
{
flag = 1;
break;
}
}
return flag;
}
//Main function
int main(void)
{
//varaiable initialization
char input[MAX_LIMIT];
char *word[2];
char delimiter[] = ", ";
printf("\n");
//get the input string from the user
printf("Enter input string: ");
fgets(input, MAX_LIMIT, stdin);
size_t ln = strlen(input) - 1;
//if no comma in the string entered by user
if(Commacheck(input) == 0)
{
printf("No comma in string.\n\n");
}
//When comma is present in the input string
else
{
char *ptr = strtok(input, delimiter);
int count = 0;
while(ptr != NULL)
{
word[count++] = ptr;
ptr = strtok(NULL, delimiter);
}
//print the first and second word of strings
printf("String 1: %s\n", word[0]);
printf("String 2: %s\n\n", word[1]);
}
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Exercise 10840 X WORK AREA RESULTS Write the definition of a function named rcopy that reads all the strings remaining to be read in standard input and displays them, one on a line with no other spacing, onto standard output IN REVERSE ORDER. So if the input was: here comes the sun the output would be sun the comes here The function must not use a loop of any kind (for, while, do-while) to accomplish its job.arrow_forwardI need help writing a java code that counts vowel in a sentence MUST use while looparrow_forwardoutput should be the same in the sample outputarrow_forward
- program4_1.pyWrite a program that uses a for loop and the range function to examine all integers from 999 down to zero. Code in the loop should print multiples of 40 on one line separated by spaces, but with only six on each line. See Required Output. Use a counter to determine when six multiples have been printed. A counter is a variable that is initialized to zero and incremented by one when the event to be counted occurs. Include pseudocode.arrow_forwardPlease help me solve this problem C. Chess Boundary Positions: Write a program called chess_pos.py On a chessboard, positions are marked with letters between a and h for the column and a number between 1 and 8 for the row. Give a 2 character input string with a letter (a-h) and a number (1-8), print "Corner" if the value indicates a square on a corner. Print "Border" if the value indicates a square on an edge of the board. Otherwise, print "Inside".arrow_forwardThis is C programming. Please fill in the blank. Code is to copy string and print backward. /* Requirement: We’ll initialize a string (I’ll use “Hello World”). Then, create a second string and copy the first string over, but backwards, using a loop. Print both strings. For example: string 1 is “Hello World”, string 2 would be “dlroW olleH”. */ /*Copy Strings Backward Input String1: Hello World*/ #include<stdio.h> #define str_len __1__ //str_len = hello + space + world + null char LEN __2__ print_string(__3__ str[__4__]); __5__ copy_string(__6__ s1[__7__], __8__ s2[__9__]); int main() { __10__ str1[]= "Hello World"; __11__ str2[__12__]; //loop and copy each character over // until the array reaches null character copy_string(__13__, __14__); //printing back by calling function print_string printf("String1: "); print_string(__15__); printf("\nString2: "); print_string(__16__); } /* Copy one string to another by looping backward. Need 2 index variables to keep track of each…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





