Question

this assignment should be delivered in C language

Program 4 will prompt the user for one or two token, space delimited, inputs of at most 20 characters. If the user provides more than 20 characters before a newline is reached print the provided error message. If the number of tokens is incorrect, print the appropriate error message. If the input is correct, print the appropriate token types. Prompt the user for input (and provide output) until the user provides a single STR token quit (case insensitive). The program should quit immediately without output. 1 2 3 ERROR Incorrect number of tokens found 12345 678901 23456789 012345 ERROR Input string too long Some 1 STR INT tuiq STR. QuIt

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot of the code:

//Define the function void processed token (char *string //Declare and initialize the variable int gap, num 1, status 1, floa

//Else part else //Print the word printf(STR ) //Update the variable found 1; //End of else part //End of else part //initia

//Increase the length by 1 sizett num 0 ; //End of else if part //Increase the string by 1 string++ //End of while loop /Chec

//Display the word printf (STR) //Increase the value by 1 found i //End of else part //End of else part //End of the functi

processed token (string) printf(in) //End of if condition //Else condition. else //Display the statement printf (ERROR! In

Sample Output:

1 2 3 ERROR! Incorrect number of tokens found. >1234567890123456789012345 ERROR! Input string too long Some 1 STR INT tuiq ST

Code to copy:

//Include the required header files.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//Define a function for the checking
//of tokens.
int Token_validation(char *string)
{
//Declare the variables.
int gap = 0, num = 1;
  
//Begin the while loop.
while(*string!='\0')
{
//Check the condition.
if(*string == ' ')
{
//Condition for gap.
if(gap == 1)
{
//Return the value.
//For wrong or no tokens.
return 0;   
  
}//End of if condition.
  
//Increase the gap by 1.
gap++;
  
}//End of if condition.
  
//Increase the string by 1.
string++;

}//End of while loop.
  
//Return the value for valid
//tokens.
return 1;

}//End of the function.

//Define the function.
void processed_token(char *string)
{
//Declare and initialize the variable.
int gap = 0, num = 1, status = 1,
float_num = 0, point=0, size = 0, found=0;

//Begin the while loop.
while(*string!='\0')
{
//Check the condition for gap.
if(*string == ' ')
{
//Check the condition for digit.
if(num == 1)
{
//Check the condition for
//floating point numbers.
if(float_num == 1)
{
//Print the word.
printf("FLOAT ");   
  
}//End of if condition.
  
//Else condition.
else
{
//Print the word.
printf("INT ");
  
}//End of else condition.

}//End of if condition.
  
//Else part for the non-num
//inputs.
else
{
//Check the condition for
//one character.
if(size == 1)
{
//Print the word.
printf("CHAR ");
  
}//End of if condition.
  
//Else part.
else
{
//Print the word.
printf("STR ");
  
//Update the variable.
found = 1;
  
}//End of else part.
  
}//End of else part.
  
//initialize the variables.
num = 1;
size = 0;
float_num = 0;
gap++;
  
}//End of if condition.
  
//Else if condition.
else if(*string=='.' && num == 1)
{
//Check the condition for point.
if(point == 0)
{
//Update the variables.
float_num = 1;
num = 1;
  
}//End of  
  
//Else condition.
else
{
//Update the variables.
float_num=0;
num = 0;

}//End of else part.
  
//Increase the point by 1.
point++;
  
}//End of else part.

//Condition for no num.
else if(!(*string>='0' && *string<='9'))
{
//Increase the length by 1.
size++;
num = 0;
  
}//End of else if part.
  
//Increase the string by 1.
string++;
  
}//End of while loop.

//Check the if condition.
if(num == 1)
{
  
//Check the condition.
if(float_num == 1)
{
//Display the word.
printf("FLOAT ");
  
}//End of if condition.
  
//Else part.
else
{  
//Display the word.
printf("INT ");
  
}//End of else part.
  
}//End of if condition.

//Else part.
else
{
  
//Check the condition.
if(size == 1)
{
//Display the word.
printf("CHAR ");
  
}//End of if condition.
  
//Else condition.
else
{
  
//Display the word.
printf("STR ");
  
//Increase the value by 1.
found = 1;
  
}//End of else part.
  
}//End of else part.

}//End of the function.

//Define the main() function.
int main()
{
//Declare the variable.
char string[21];
  
//Begin the while condition.
while(1)
{
//Display the sign.
printf(">");
  
//Input the string.
gets(string);
  
//Check the condition for string.
if(strcmp(string,"QuIt") == 0)
{
//Break the program.
break;
  
}//End of if condition.
  
//Check the length of string.
if((strlen(string)) >= 20)
{
//Display the statement.
printf("ERROR! Input string too long.\n");
  
}//End of if condition.
  
//Else part.
else
{
//Check the condition.
if(Token_validation(string))
{
//Call the function.
processed_token(string);
printf("\n");
  
}//End of if condition.
  
//Else condition.
else
{
//Display the statement.
printf("ERROR! Incorrect number of tokens found.\n");
  
}//End of else part.
  
}//End of else part.

}//End of while condition.
  
}//End of main() function.

Add a comment
Know the answer?
Add Answer to:
this assignment should be delivered in C language Program 4 will prompt the user for one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java language: C Write a game program that allows the user to collect 4 tokens hidden...

    Java language: C Write a game program that allows the user to collect 4 tokens hidden in an array (cells) of size 10. The program asks the user to select a cell. Determine if there is a token in that cell or not, and give the user appropriate feedback. This program should keep letting user to select until the all tokens are collected. The program should display the total number of selections. Use rand_position Example input/output: There are four tokens....

  • 1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or **...

    1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...

  • program should be in c language. thank you for helping me. 1 of 4 CSCI 281...

    program should be in c language. thank you for helping me. 1 of 4 CSCI 281 LAB 5 -STACKS AND A CALCULATOR ASSIGNMENT Using 2 stacks to implement a calculator CALCULATOR 1. User input of two types. Integer values and associated tokens(+ 2. As the user needs to enter the input in the following manner: +5/17-3 9+2 8+7 You should use a looping scanf to allow the user to enter digit, then a char, then a digit, then a car...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • **This is for the C Language. Trigonometric Calculator Specification You are required to write a program...

    **This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...

  • Division by Zero Problem: Create a program titled Division. Have the program prompt the user "Enter...

    Division by Zero Problem: Create a program titled Division. Have the program prompt the user "Enter numerator and denominator" and store the two values entered. (If you wish the user to "Enter numerator/denominator" be sure to adjust your data gathering variables to include a holder variable for the slash character.) Include a function titled Quotient that takes 2 integers as input and provides the quotient of the 2 integers as integer output. (The remainder is truncated. Thus, 5/3 will be...

  • PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for...

    PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for the user's most challenging course at Wilmington University. The second prompt should ask for the user's second most challenging course. The red boxes indicate the input from the user. Your program should respond with two copies of an enthusiastic comment about both courses. Be sure to include the input provided by the user to display the message. There are many ways to display a...

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

  • C++ Program Write a do-while loop that continues to prompt a user to enter a number...

    C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...

  • C++ (1) Write a program to prompt the user for an input and output file name....

    C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT