Thread: [Help]Syntax error...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    6

    [Help]Syntax error...

    Code:
    #include <WinSock.h>
    #include <mysql.h> 
    #include <stdlib.h> 
    #include <stdio.h> 
    #include <password.hh> 
    
    
    MYSQL     *conn;
    MYSQL_RES *res;
    MYSQL_ROW  row;
    
    
    unsigned long how_rows (void);
    void print_data(void);
    char* to_upper (char*);
    void print_table(void);
    void print_line (void);
    
    
    //----------------------------------------------------------
     
    int main (int argc, char* argv[])
    {
        unsigned long ul;
        int i;
        char databases[25][30];
        char query[30];
        char temp[30], table[30];
        
        conn = mysql_init ( NULL );
        mysql_real_connect (conn,"","root",password(),
                "",3306,NULL); error C2198: 'mysql_real_connect' : too few arguments for call
    
    
        mysql_query(conn,"show databases");
        res = mysql_store_result(conn);
    
    
        ul = how_rows();
        i=0;
        system("clear");
        printf("\nThere are %lu databases\n",ul);
        puts("=====================");
    
    
        while ( row = mysql_fetch_row(res) )
        {
            strcpy(databases[i],row[0]);
            puts(databases[i]);
            i++;
        }
        for ( i = 0; i < ul; i++ )warning C4018: '<' : signed/unsigned mismatch
        {
            if ( strcmp(databases[i],"mysql") == 0 )
                continue;
            sprintf(query,"use %s",databases[i]);
            mysql_query(conn,query);
            strcpy(temp,databases[i]);
            fprintf(stdout,"\nThe database %s consists tables:\n",
                    to_upper(temp));
            puts("==========================================");
            print_data();
            getchar();
    //        usleep(900000); 
        }
        while(1)
        {
            fprintf(stdout,"What database do you want to use? (0-quit): ");
            fgets(temp,29,stdin);
            temp[strlen(temp)-1] = '\0';
    
    
            if ( strcmp(temp,"0") == 0 )
                break;
            for ( i = 0; i < ul; i++ )warning C4018: '<' : signed/unsigned mismatch
            {
                if ( strcmp(temp,databases[i]) == 0 )
                {
                    while(1)
                    {
                        fprintf(stdout,"What table do you want to see? ");
                        fprintf(stdout,"(0-quit): ");
                        fgets(table,29,stdin);
                        table[strlen(table)-1] = '\0';
    
    
                        if ( strcmp(table,"0") == 0 )
                            break;
                        sprintf(query,"select * from %s.%s",temp,table);
                        mysql_query(conn,query);
                        print_table();
                    }
                }
            }
        }    
        mysql_close(conn);
        exit(0);
    }
    //----------------------------------------------------------  
    unsigned long how_rows (void)
    //----------------------------------------------------------  
    {
        return (unsigned long) mysql_num_rows(res);
    }
    //----------------------------------------------------------  
    void print_data(void)
    //----------------------------------------------------------  
    {
        mysql_query(conn,"show tables");
        res = mysql_store_result(conn);
        while ( row = mysql_fetch_row(res) )
        {
            fprintf(stdout,"%s\n",row[0]);
        }
    }
    //----------------------------------------------------------  
    char* to_upper (char* name)
    //----------------------------------------------------------  
    {
        char *p = name;
        while (*p)
        {
            *p = toupper(*p);
            p++;
        }
        return name;
    }
    //----------------------------------------------------------  
    void print_table(void)
    //----------------------------------------------------------  
    {
        MYSQL_FIELD *field;
        unsigned int i, j, column_length;
        
        res = mysql_store_result(conn);
        
        mysql_field_seek(res,0);
        for ( i = 0; i < mysql_num_fields(res); i++ )
        {
            field = mysql_fetch_field(res);
            column_length = strlen(field->name);
            if ( column_length < field->max_length )
                column_length = field->max_length;
            if ( column_length < 4 && !IS_NOT_NULL(field->flags) )
                column_length = 4;
            field->max_length = column_length;
        }
        print_line();
        fputc('\n',stdout);
        mysql_field_seek(res,0);
        for ( i = 0; i < mysql_num_fields(res); i++ )
        {
            field = mysql_fetch_field(res);
            fprintf(stdout," %-*s ",field->max_length,field->name);
        }
        fputc('\n',stdout );   print_line();
        fputc('\n',stdout);
        while ((row = mysql_fetch_row(res)) != NULL)
        {
            mysql_field_seek(res,0);
    
    
            for ( i = 0; i < mysql_num_fields(res); i++ )
            {
                field = mysql_fetch_field(res);
                if ( row[i] == NULL )
                    fprintf(stdout," %-*s ",field->max_length,"NULL");
                else
                if ( IS_NUM(field->type) )
                    fprintf(stdout," %*s ",field->max_length,row[i]);
                else
                    fprintf(stdout," %-*s ",field->max_length,row[i]);
            }
            fputc('\n',stdout);    }
        fputc('\n',stdout); {   mysql_free_result(res);
    }
    //---------------------------------------------------------- 
    void print_line (void)
    //----------------------------------------------------------  
    {
        MYSQL_FIELD *field;
        unsigned int i, j;
        
        mysql_field_seek(res,0);
        for ( i = 0; i < mysql_num_fields(res); i++ )
        {
            field = mysql_fetch_field(res);
            for ( j = 0; j < field->max_length + 2; j++ )
                fputc('=',stdout);
        }
    }
    1 errors and 2 warning
    Last edited by athena21191; 11-16-2012 at 02:50 AM.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The error is in the code just BEFORE this function. That's what compilers do when you miss a } or a ; someplace that the compiler can't quite pin down. They "blame" the code after it.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    Quote Originally Posted by Adak View Post
    The error is in the code just BEFORE this function. That's what compilers do when you miss a } or a ; someplace that the compiler can't quite pin down. They "blame" the code after it.
    How to fix them?
    Thanks

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    At least you recognise the code is C now - or maybe not - why not try the windows programming forum too?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    How many arguments does mysql_real_connect take, and how many arguments are you passing to it? The error message is kindly telling you that you're passing too few arguments.

    Edit: hm, you have a duplicate thread here: Help me to fix problem . Please don't post more than one thread for the same topic.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 11-30-2011, 11:55 AM
  2. Error "in function 'main' syntax error before 'int' Help Please
    By blackhat11907 in forum C Programming
    Replies: 5
    Last Post: 08-20-2011, 07:05 PM
  3. error C2061: syntax error : identifier
    By maninboots in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2009, 05:40 AM
  4. error C2143: syntax error : missing ')' before ';'
    By steve1_rm in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 11:06 AM
  5. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM