List:General Discussion« Previous MessageNext Message »
From:Thomas R. Bedell Date:March 22 1999 3:28am
Subject:RE: Why the error here?
View as plain text  
Hello,

I am trying to use:

mysql_create_db in a C program.  It compiles and links OK.  But when you execute the
program, I get the following error.

#include "mysql.h"
#include "mysql.h"
#include <stdio.h>
#include <stdlib.h>

MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
char *db = "db";

void exiterr(int exitcode)
{
fprintf( stderr, "%s\n", mysql_error(&mysql) ); 
exit( exitcode );
}

main()
{
char db;
printf("Enter a name for your new database\n\n"); 
scanf("%s", &db);
if (!(mysql_connect(&mysql,"localhost","root",""))) 
exiterr(1);
if (mysql_create_db(&mysql, &db))
exiterr(2);

mysql_free_result(res);
mysql_close(&mysql);
}

When I run my code here is what I get:
[root@oscar mysql_c]# ./connect
Enter a name for your new database

homes
Segmentation fault
BUT....  The database is added to mysql.  I can connect to it, and view the "empty set". 
Why the segmentation fault???
Thank you in andvance.

Tom Bedell
Tom@stripped

Thread
Why the error here?Thomas R. Bedell22 Mar
  • Re: Why the error here?Thimble Smith22 Mar
RE: Why the error here?Thomas R. Bedell22 Mar
Re: Why the error here?Derick H Siddoway22 Mar
Re: Why the error here?Sasha Pachev22 Mar
Re: Why the error here?Derick H Siddoway22 Mar