please only C language, not C++ or other languages, and type the answer DO NOT u
ID: 3846550 • Letter: P
Question
please only C language, not C++ or other languages, and type the answer DO NOT use handwriting
The assignment should be delivered in C language Program 2 should prompt the user for input with the right carrot (" > "). When the user types in input, it should be treated as space delimited input and terminated by the newline character. The program should only take in user input of at most 65 characters (ignoring any more). The program will print either STR or INT for each input token. If the input token is an integer, it should output INT, otherwise it should output STR. The output should be on a single line and terminated by a newline character. > User 12 Input 3.14 Goes 12345 Here STR INT STR STR STR INT STRExplanation / Answer
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
//can take input pto 65 char
#define MAX 65
int main()
{
//declare character array to take input
char buffer[MAX];
char token[65];
int i = 0, j = 0, notInt = 0,k=0;
printf("> ");
//take ser input
fgets(buffer, sizeof(buffer), stdin);
buffer[strlen(buffer)-1] = '';
//printf("%s ", buffer);
while (buffer[i] != '')
{
//check if space then put the for token
if (buffer[i] != 32)
{
token[j++] = buffer[i++];
continue;
}
if (buffer[i] == 32)
{
token[j] = '';
j = 0;
}
k = 0;
while (token[k] != '')
{
if (token[k++] == '.')
notInt = 1;
}
if (atoi(token) != NULL && notInt!=1)
printf("INT ");
else
{
if( strlen(token) > 0)
printf("STR ");
else
i++;
}
notInt = 0;
}
token[j] = '';
if (atoi(token) != NULL)
printf("INT ");
else
{
if (strlen(token) > 0)
printf("STR ");
}
}
-----------------------------------------------------------
//output
> User 12 Input 3.14 Goes 12345 Here
STR INT STR STR STR INT STR
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.