i asked this on the C++ forum but someone told me to try it here on C.
here's my first program there are some error with this program, i can't debug it. what's the problem?

#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
    int strlen, a, b,c;
    int data_type, var;
    char dtypechecker;
    char *str;
    clrscr();

    data_type=0;
    var=1;
    b=0;
    gets(str);
    str+='\0';
}
bool is_alpha(char ch)
{
    return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
}

for(a=0;a<strlen;a++)
{
    if(data_type!=1)
    {
        if(str[a]==isalpha)
        {
            dtypechecker[b]=str[a];
            b++;
        }
        if(str[a]==':')
        {
        }
        if(b==0)
        {
        //do nothing
        }
        else
        {
            dtypechecker==[10];
            switch(dtypechecker)
            printf("int\t data ytpe case 'int': var=0");
            printf("int\t data ytpe case 'char':    var=0");
            printf("int\t data ytpe case 'float':   var=0");
            printf("int\t data ytpe case 'double':  var=0");
            printf("int\t data ytpe case default=data type error");
            error==1;               
        }
        if(error!=1)
        {
            else
            {
                exit(1);
            }
        }
    }
    if(var!=1)
    {
        if(str[a]==isalpha)
        {
            varchecker[c]==str[a];
            c++;
        }
    }
    else if(str[a]==isdigit)
    {
        if(c==0)
        {
            error=1;
        }
        else
        {
            varchecker[c]==str[a];
            c++;
        }
        else if(str[a]=='*')
        {
            if(c==0)
            {
                varchecker[c]=str[a];
                printf("\n\t*\t pointer");
                c++;
            }
            else
            {
                error=1;
            }
            else if(str[a]==',')
            {
                if(c==0||str[a+1]==';')
                error=1;
            }
            else
            {
                for(d=0;d<c;d++)
                {
                    printf("\t variable\n");
                    printf("\t separator \n");
                }
                else if(str[a]==';')
                {
                    if(a+1!=strlen(str);c==0)
                    {
                        //error replacing semi colon
                        printf("\n\tlexeme\t\t token");
                        printf("%s",dtypechecker);
                        printf("\t data type \n");
                    }
                    else
                    {
                        for(d=0;d<c;d++)
                        {
                            printf("%c",varchecker);
                            printf("\t variable");
                            printf(";\t semi colon");
                        }
                    }
                }
            }
        }
    }
    return 1;
}

Recommended Answers

There are numerous problems with your code.

  1. Do not use conio.h if you want portable code.
  2. Avoid the dangerous use of gets ... use fgets instead.
  3. ...
    ...

This sample code below may help you get started ...

It is good to develope in steps, making sure that …

Jump to Post

All 2 Replies

There are numerous problems with your code.

  1. Do not use conio.h if you want portable code.
  2. Avoid the dangerous use of gets ... use fgets instead.
  3. ...
    ...

This sample code below may help you get started ...

It is good to develope in steps, making sure that at each step your code compiles and runs with the expected output.

Always keep a copy of your last working 'step' ... so that you can go back to that (working) stage of developement and start again ... (if you can not find the 'bug').

include <stdio.h>
/* #include <conio.h> */
#include <string.h>
#include <ctype.h>


int is_alpha( char ch ) /* but why not use C provided isalpha ? */
{
    return ( ch >= 'A' && ch <= 'Z' ) || ( ch >= 'a' && ch <= 'z' );
}


int main()
{
    int i, str_len;
    char str[ 1024 ], *p;

    /* clrscr();  */

    printf( "Enter a line of C code to check if valid: " );
    fgets( str, sizeof(str), stdin  );
    p = strchr( str, '\n' );
    if( p ) *p = 0; /* 0 terminate to rid '\n' char at end ... */
    else
    {
        fputs( "The buffer size was too small ... enlarge and recompile.\n ", stderr );
        getchar();
        return 1;
    }


    str_len = strlen( str );
    printf( "You entered: %s\n", str );
    printf( "With length %d characters.", str_len );

    for( i = 0; i < str_len; ++i )
    {

        /*  your code here ... */

    }

    printf( "\n\nPress 'Enter' to continue/exit ... " );
    getchar();

    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.