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
  1. Home
  2. General Programming
  3. C#
  4. i don't know at what is zed using in this code the ''if(mode == 'c')",pls help!

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

Scheduled Pinned Locked Moved C#
databasehelpperformancequestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Sturza
    wrote on last edited by
    #1

    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;
    

    }

    P D 2 Replies Last reply
    0
    • 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;
      

      }

      D Offline
      D Offline
      Dilan Shaminda
      wrote on last edited by
      #2

      it just check the mode you passed as a parameter is equal to 'c'. If it is equal to 'c' then create an empty file for output operations ("w"). else open a file for update ("r+") (both for input and output).

      A 1 Reply Last reply
      0
      • 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;
        

        }

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        That's C code, not C#. What are you expecting from this forum?

        1 Reply Last reply
        0
        • D Dilan Shaminda

          it just check the mode you passed as a parameter is equal to 'c'. If it is equal to 'c' then create an empty file for output operations ("w"). else open a file for update ("r+") (both for input and output).

          A Offline
          A Offline
          Alex Sturza
          wrote on last edited by
          #4

          thank you!!

          D 1 Reply Last reply
          0
          • A Alex Sturza

            thank you!!

            D Offline
            D Offline
            Dilan Shaminda
            wrote on last edited by
            #5

            You are welcome :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

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