-
having problems
i still have problem
i tried to solve the first function which checks if there is an article or not in the sentence as follow
Code:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
typedef char* token_t ;
typedef token_t token;
int get_next_token();
int main()
{int y;
y=get_next_token();
if(y==0)
printf("No Article \n");
else
printf("GOOD PHRASE ");
return(0);
}
/*******************************/
int get_next_token()
{
token string[30];
token str1[10];
int i=0,x;
printf("Enter the sentence\n");
scanf("%s",string);
while(isspace((string[i])) )
{ str1[i]=string[i] ;
i++;
}
x=article(str1);
if(x==0)
return(0);
else
return(0);
}
/* the following function returns 1 if there is article otherwise it returns 0*/
int article (token str)
{
if((strcmp(str,"The")==0) ||(strcmp( str, "A")==0)||
(strcmp(str,"the")==0)||(strcmp(str,"a")==0))
return(1);
else
return(0);
}
but the compiler gave me errors such as could not convert
' char * ' to int
-
I don't know what it is you want to do, so I only got rid of the warnings/errors.
Code:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
typedef char* token_t ;
typedef token_t token;
int get_next_token();
int article (token str);
int count=0;
int main()
{
int y;
y = get_next_token();
if(y==0)
printf("No Article \n");
else
printf("GOOD PHRASE %d",count);
return(0);
}
/*******************************/
int get_next_token()
{
token string[30];
token str1[10];
int i=0,x;
printf("Enter the sentence\n");
scanf("%s",string);
while( isspace((int)string[i]) )
{
str1[i] = string[i] ;
i++;
}
x = article( (char*) str1 );
if(x==0)
return(0);
else
return(0);
}
/* the following function returns 1 if there is article otherwise it returns 0*/
int article (token str)
{
if( (strcmp(str,"The")==0) || (strcmp( str, "A") == 0) || (strcmp(str,"the")==0) || (strcmp(str,"a") ==0))
return(1);
else
return(0);
}
-
What are you trying to do here?
Code:
if(x==0)
return(0);
else
return(0);
Just return x
Don't name your variable string (it's a reserved word in C++).
-
the goal of the program
I asked to write a program works as parser This program implements an interpreter in the C language,which will read a sentence at atime from the user and print :Good:<n> words when the input noun phrase is grammatically correct,and <n> is the total number of words in the phrase.If the input is grammatically incorrect,it will print :Bad phrase to the user.
The sentence is correct(according to this program) if it contains
1.article(a,the)
2.adjective {hungry,black,white , thirsty}
3.noun {cat,dog}
the sentence may contain more than one objective or no objective at all and the program must contain the foolowing function getnexttoken(); noun_phrase();
article(); noun();
example:
input output
The cat Good<2>words
The black dog. Good<3>words
The white hungry cat. Good<4>words
a hungry Bad phrase
some members suggested to use small steps and solve the easiest problem an so on .
-
sorry. i did mistake
the second return must be return(1)