Thread: having problems

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    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

  2. #2
    Registered User The Junglist's Avatar
    Join Date
    Nov 2002
    Posts
    42
    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);
    }

  3. #3
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    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++).

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    7

    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 .

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    7
    sorry. i did mistake
    the second return must be return(1)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM