I am working on Dev-C++. But the output window closes as soon as the program gets executed. I read through their forums and I tried using getch() but it isn't of any use.
conn.c
Code:
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include "C:/Program Files/MySQL/MySQLServer5.1/include/mysql.h"
int main(int argc, char **argv)
{
MYSQL *conn;
conn = mysql_init(NULL);
if (conn == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
if (mysql_real_connect (
conn, /* pointer to connection handler */
"localhost", /* host to connect to */
"root", /* user name */
" ", /* password */
"test_db", /* database to use */
0, /* port (default 3306) */
NULL, /* socket or /var/lib/mysql.sock */
0 ) == NULL) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
if (mysql_query(conn, "create database test_db")) {
printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
exit(1);
}
mysql_close(conn);
printf("Database successfully created.");
getchar();
return (0);
}
any thoughts on why this happens?