Thread: C Segmenation fault

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    1

    C Segmenation fault

    Hello,
    Does sombody know what could be wrong with the following code:
    It compiles alright but when i run the binary file it give's a Segmentation fault.

    Code:
    #include "/usr/local/mysql/include/mysql/mysql.h"
    #include <stdio.h>
    #include <string.h>
    
    main() {
    
       MYSQL *subconn;
       MYSQL *domeinconn;
       MYSQL_RES *sub;
       MYSQL_RES *domein;
       MYSQL_ROW subrow;
       MYSQL_ROW domeinrow;
    
    
       char *server = "xxx";
       char *user = "xxx";
       char *password = "xxx";
       char *database = "xxx";
    
       subconn = mysql_init(NULL);
       domeinconn = mysql_init(NULL);
    
    
       if (!mysql_real_connect(subconn, server,
             user, password, database, 0, NULL, 0)) {
          fprintf(stderr, "%s\n", mysql_error(subconn));
          exit(0);
       }
    
     if (!mysql_real_connect(domeinconn, server,
            user, password, database, 0, NULL, 0)) {
          fprintf(stderr, "%s\n", mysql_error(domeinconn));
          exit(0);
       }
    
       /* send SQL query */
       if (mysql_query(subconn, "SELECT * FROM table1")) {
          fprintf(stderr, "%s\n", mysql_error(subconn));
          exit(0);
       }
    
       sub = mysql_use_result(subconn);
       domein = mysql_use_result(domeinconn);
    
    
       while ((subrow = mysql_fetch_row(sub)) != NULL) {
    
            if(mysql_query(domeinconn, "SELECT domein_naam FROM table2 WHERE domein_id=3")) {
                    fprintf(stderr, "%s\n", mysql_error(domeinconn));
                    exit(0);
            }
    
            while ((domeinrow = mysql_fetch_row(domein) != NULL) {
                    printf("%s%s\n", domeinrow[0], subrow[2]);
            }
       }
    
       mysql_close(domeinconn);
       mysql_close(subconn);
    }
    Greetz
    Last edited by OrbiT^; 04-19-2005 at 12:25 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird seg fault
    By Vermelho in forum C Programming
    Replies: 3
    Last Post: 05-10-2008, 08:27 PM
  2. Segmenation Fault
    By sunoflight77 in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2005, 12:07 AM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 03:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  5. segmenation fault when executing
    By v3dant in forum C Programming
    Replies: 2
    Last Post: 11-15-2004, 04:07 PM