this Assignment should be delivered in C language Program 3 should prompt the us
ID: 3846177 • Letter: T
Question
this Assignment should be delivered in C language
Program 3 should prompt the user for a space delimited input string with the ">" of at most 65 characters. If the user provides more than two to print the provided error message and re-prompt the user for an input string until the user provides one or two tokens. When the input is correct, print the appropriate token type (as in Program 2) for each token typed and exit. > The User Entered 5 Things ERROR! Incorrect number of tokens found. > 7 Total INT STRExplanation / Answer
#include <stdio.h>
char* findType(char* str){
char* type="STR";
int flag=1; // assume that sstr is numeric
int num_flag=1; // assume that it is integer
int k=0;
while(k<sizeof(str)){
if((str[k]>=0&&str[k]<=9)||str[k]=='.'){
flag=1;
if(str[k]=='.')num_flag=0;
}
else{
flag=0;
}
}
if(flag==1){
if(num_flag==0)
type="INT";
else type="FLOAT";
}
return type;
}
char* substring(char* s,int p, int l) {
char* sub;
int c = 0;
while (c < l) {
sub[c] = s[p+c-1];
c++;
}
sub[c] = '';
return sub;
}
int main(void) {
char* str; // string of atmost 65 characters
char** type_token;
int inp_flag=1;
while(inp_flag==1){
printf(" enter input string : ");
scanf("%s",&str);
int i=0;
int n=1;
int start=0,curr=0;
while(i<sizeof(str)){
if(i<sizeof(str)-1){
if(str[i]==' '&&str[i+1]!=' '){
type_token[n]=substring(str,start,curr-start);
start=i+1;
n++;
}
}
i++;
curr++;
}
printf(" tokens : %d",n);
if(n==1||n==2)
{
int j=0;
while(j<sizeof(type_token[n])){
printf(" %s",findType(type_token[j]));
}
}
else{
inp_flag=0;
printf(" ERROR! Incorrect number of tokens found");
}
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.