#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h> 
int main()
{
      char org[50],r[50],m[50],a;
      int i,j,c=0,length=0,h=0,g=0,z;
      char token [3] [20] = { "void", "main", "int"};
      printf("\nenter a line:");
      gets(org);
      for(i=0;org[i]!='\0';i++)
      {
      length++;
      }
      for(h=0;h<3;h++)
       {
         for(g=0;g<length;g++)
         {     
          z=strcmp(org[g],token [h]);                      
          if(z==0)
          printf("Keyword:%s\n\n",m);
          else
          printf("NO_Keyword:%s\n\n",m);
         }
       }

 printf("\n");      
      system("pause");
      return 0;
}

it is showin this warning....[Warning] passing arg 1 of `strcmp' makes pointer from integer without a cast.
i am gettin command prompt as output in dev c++ software but when i enter string in command prompt and press enter then command prompt goes stop automatically.
tell me what is wrong in this program....and what is this wraning?????

Edited 5 Years Ago by Narue: added code tags

First, Welcome to the forum, Susees! ;)

Second, Always use code tags around your code - otherwise it's very hard to study your code, because the forum software uses the wrong fonts, and squishes it all over to the far left hand side of the page.

In your call to strcmp(), your first parameter is a char, not a pointer to a string. Org[g] is not a 2 dimension array like token[][] is.

You could pass it just org - that can be used as a pointer. (You can't change the address of it, but it will point to the string it holds.

dude i got a program token sepration.
it means is that user will give a input line to you and you have to identify that what are the keywords,special symbols present in the given input line.
so if i enter susees default void see main ; '().....then the program should identify that default,void,main are the keyword and ;'() are special symbols.

if you have any idea how to do it.then please tell me....if you would give me program then it would be my pleasure. and i will be highly grateful to you.........please reply me...

if you would give me program then it would be my pleasure.

We don't do that here. We help you write your own code, but that's it. You need to ask specific questions and someone will guide you toward a solution rather than write it for you.

So, what's your new question now that Adak has so kindly helped you fix the error?

thinks for replying me....then just compile my program and tell me that why it is not showing the output...?? why command prompt goes off after entering the string as input????? if you can figure out then just let me know....

Hello,
You need realize that if you enter the line:
void main
You compare every token with the line:
"main" with "void main"
and
"void" with "void main"
And them will be always different.
You need to isolate the tokens inside the string.
I hope that this can be useful.

sorry...i couldn't understand what did u said....did u compile my program??? it's compiling very well but it's getting one warning....and i am not getting the output.
so please compile my program and tell me some suggestion....

Hi,

I have modified a little your code. It still does not work, but you can learn some things. I will correct your code, but I won't write your program:

#include<stdio.h>
#include<string.h>
#include<ctype.h> 
int main()
{
      char org[50],r[50],m[50],a;
      int i,j,c=0,length=0,h=0,g=0,z;
      char token [3] [20] = { "void", "main", "int"};
      printf("\nenter a line:");
	//gets READS A COMPLETE LINE. IF org HAS PLACE FOR 50 bytes AND THE USER WRITES MORE THAN 50 BYTES
	//THEN IT WRITES BEYOND THE ROOM. THIS ENDS WITH A RUN TIME ERROR.
      fgets(org, 50, stdin);
	//FGETS READ UP TO 50 CHARACTERS FROM THE STREAM stdin (STANDARD INPUT) AND
	//SAVES THEM ON org. IF THE USER WRITES MORE THAN 50 CHARACTERS ONLY 50 ARE WRITTEN.
      for(i=0;org[i]!='\0';i++)
      {
      length++;
      }
      for(h=0;h<3;h++)
       {
         for(g=0;g<length;g++)
         {     
	  //I HAVE MODIFIED THE NEXT LINE. LOOK AT THE &.
	  //org IS A POINTER TO THE FIRST CHARACTER OF THE STRING
	  //&org[2] IS A POINTER TO THE THIRD CHARACTER OF THE STRING
	  //&org[n] IS A POINTER TO THE n + 1 th CHARACTER OF THE STRING
	  //org[2] IS THE THIRD CHARACTER OF THE STRING
          z=strcmp(&org[g],token [h]);                      
          if(z==0)
          printf("Keyword:%s\n\n",m);
          else
          printf("NO_Keyword:%s\n\n",m);
         }
       }

 	printf("\n");      
      getchar();
      return 0;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
    char org[50],r[50],m[50],a;
    int i,j,c=0,length=0,h=0,g=0,z;
    char token [3] [20] = { "void", "main", "int"};
    printf("\nenter a line:");
    gets(org);
    for(i=0; org[i]!='\0'; i++)
        length++;
    while(g!=length) {
        for(g; g<length; g++) {

            if(org[g]==' ' || org[g]=='\n' || org[g]=='\t') {
                g++;
                break;
            }
            m[c++]=org[g];
        }
        m[c]='\0';
        for(h=0; h<3; h++) {
            z=strcmp(m,token [h]);
            if(z==0) {
                printf("\n %s is Keyword",m);
                break;
            }
        }
        if(h==3)
            printf("\n %s is not a Keyword ",m);
        c=0;
    }
    printf("\n");
    return 0;
}

Edited 5 Years Ago by Narue: Fixed formatting and added code tags

Ashok1514,
You may have missed earlier comments to the effect that this forum is not about providing complete solutions. It is up to the original poster to try to learn from help offered, and write his/her own code.

That said, when posting code in the forum, please use [ CODE ] blocks. This numbers the lines, uses a fixed-width font, and maintains indentation, similar to a programming IDE or simple text-editor. The simplest solution is probably to click the [ CODE ] icon at the top of the editor, and then paste your code between [ CODE ] and [ /CODE ].

This article has been dead for over six months. Start a new discussion instead.