Thread: help me with void function

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    19

    help me with void function

    can anyone help me to transform this function to a void function, using the pointer address??

    Code:
    int main(){		
    
    	...
    	MYSQL	*p_connection;
    	...
    	p_connection = Initiate_mysql(p_connection);	
            ...
       
    }
    
    MYSQL* Initiate_mysql(MYSQL* p_connection){
    	const char*	host = "xxxx";
    	const char*	user = "xxxx";
    	const char*	password = "xxxx";
    	const char*	database = "xxxx";	
    
    	p_connection = mysql_init(NULL);	
    
    	if (!mysql_real_connect(p_connection,host,user,password,database,0,NULL,0)) {
    
    		fprintf(stderr, "Failed to connect to p_database: Error: %s\n", mysql_error(p_connection));
    
    	}
    	return p_connection;
    
    }


    thx

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Initiate_mysql should simply take an additional MYSQL** as argument and you pass in p_connection as argument.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Initiate_mysql should simply take an additional MYSQL** as argument and you pass in p_connection as argument.
    Or rather, the argument should be MYSQL ** instead of MYSQL *, and you need to pass the address of p_connection.

    Edit: You will also need to dereference p_connection inside the function, of course.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Hm. I missed that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    19
    well thats what i changed considering ur advices... plz correct me if im wrong, cuz the program is compiling without errors, but giving me error in the execution...


    Code:
    int main(){    
        
    	...
    	MYSQL	*p_Connection; 
    	...
    	Initiate_mysql(&p_Connection);	
            ...
    	
    }
    
    void Initiate_mysql(MYSQL** p_Connection){
    	const char*	Host = "xxxx";
    	const char*	User = "xxxx";
    	const char*	Password = "xxxx";
    	const char*	Database = "xxxx";
    	
    	mysql_init(*p_Connection);
    	
    	if (!mysql_real_connect(*p_Connection,Host,User,Password,Database,0,NULL,0)) {
    		fprintf(stderr, "Failed to connect to s_Value_OUTbase: Error: %s\n", mysql_error(*p_Connection));
    	}
    	
    }
    Last edited by ltcabral; 03-06-2008 at 11:02 AM.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Judging from this, you should do:
    Code:
    	*p_Connection = mysql_init(NULL);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM