Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
A

Alex Sturza

@Alex Sturza
About
Posts
10
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • what is zed doing here?
    A Alex Sturza

    i understand now,thank you very much!

    C / C++ / MFC database question

  • what is zed doing here?
    A Alex Sturza

    can i give you the entire code?maybe you will find my answer:)

    C / C++ / MFC database question

  • what is zed doing here?
    A Alex Sturza

    yes,but by the name of function says(database_delete),this function must delete something,and i don't know how it is deleting something

    C / C++ / MFC database question

  • what is zed doing here?
    A Alex Sturza

    this is C code!!!

    C / C++ / MFC database question

  • what is zed doing here?
    A Alex Sturza

    in this code?from where i need to understand that is deleting something? void Database_delete(struct Connection *conn, int id) { struct Address addr = {.id = id, .set = 0}; conn->db->rows[id] = addr;

    C / C++ / MFC database question

  • in this code,where is called database_close?pls help
    A Alex Sturza

    my bad,sry about you wasted time to read my code:))

    C / C++ / MFC help database performance tutorial question

  • in this code,where is called database_close?pls help
    A Alex Sturza

    omg,sry about that badd miss,and thanks anyway!

    C / C++ / MFC help database performance tutorial question

  • in this code,where is called database_close?pls help
    A Alex Sturza

    #include #include #include #include #include #define MAX_DATA 512 #define MAX_ROWS 100 struct Address { int id; int set; char name[MAX_DATA]; char email[MAX_DATA]; }; struct Database { struct Address rows[MAX_ROWS]; }; struct Connection { FILE *file; struct Database *db; }; void die(const char *message) { if(errno) { perror(message); } else { printf("ERROR: %s\n", message); } exit(1); } void Address_print(struct Address *addr) { printf("%d %s %s\n", addr->id, addr->name, addr->email); } void Database_load(struct Connection *conn) { int rc = fread(conn->db, sizeof(struct Database), 1, conn->file); if(rc != 1) die("Failed to load database."); } struct Connection *Database_open(const char *filename, char mode) { struct Connection *conn = malloc(sizeof(struct Connection)); if(!conn) die("Memory error"); conn->db = malloc(sizeof(struct Database)); if(!conn->db) die("Memory error"); if(mode == 'c') { conn->file = fopen(filename, "w"); } else { conn->file = fopen(filename, "r+"); if(conn->file) { Database_load(conn); } } if(!conn->file) die("Failed to open the file"); return conn; } void Database_close(struct Connection *conn) { if(conn) { if(conn->file) fclose(conn->file); if(conn->db) free(conn->db); free(conn); } } void Database_write(struct Connection *conn) { rewind(conn->file); int rc = fwrite(conn->db, sizeof(struct Database), 1, conn->file); if(rc != 1) die("Failed to write database."); rc = fflush(conn->file); if(rc == -1) die("Cannot flush database."); } void Database_create(struct Connection *conn) { int i = 0; for(i = 0; i < MAX_ROWS; i++) { // make a prototype to initialize it struct Address addr = {.id = i, .set = 0}; // then just assign it conn->db->rows[i] = addr; } } void Database_set(struct Connection *conn, int id, const char *name, const char *email) { struct Address *addr = &conn->db->rows[id]; if(addr->set) die("Already set, delete it first"); addr->set = 1; // WARNING: bug, read the "How To Break It" and fix this char *res = strncpy(addr->name, name, MAX_DATA); // demonstrate the strncpy bug if(!res) die("Name copy failed"); r

    C / C++ / MFC help database performance tutorial question

  • i don't know at what is zed using in this code the ''if(mode == 'c')",pls help!
    A Alex Sturza

    thank you!!

    C# database help performance question

  • i don't know at what is zed using in this code the ''if(mode == 'c')",pls help!
    A Alex Sturza

    struct Connection *Database_open(const char *filename, char mode)
    {
    struct Connection *conn = malloc(sizeof(struct Connection));
    if(!conn) die("Memory error");

    conn->db = malloc(sizeof(struct Database));
    if(!conn->db) die("Memory error");
    
    if(mode == 'c') {
        conn->file = fopen(filename, "w");
    } else {
        conn->file = fopen(filename, "r+");
    
        if(conn->file) {
            Database\_load(conn);
        }
    }
    
    if(!conn->file) die("Failed to open the file");
    
    return conn;
    

    }

    C# database help performance question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups