CrazyEngineers
  • MAIN.C
    /*
     * main.c
     *
     *  Created on: 15 Mar 2014
     *      Author: Aadit
     */
    
    #include 
    #include 
    #include 
    #define SUCCESS "Operation success!\n"
    #include "main.h"
    #define USAGE   printf("usage: command.\n");
    struct userbase user1;
    #include 
    int main(int argc,char *argv[])
    {
        if(check(argc,argv,&user1) == 2)
        {
            printf(SUCCESS);
        }
        else if(check(argc,argv,&user1) == CHECK_ERROR)
        {
            printf("Command not matched!\n");
        }
        else
            USAGE;
    
        assert(user1.password != NULL && user1.username != NULL);
        printf("Username =%s\nPassword = %s\n",user1.username,user1.password);
    }
    
    MAIN.H
    /*
     * main.h
     *
     *  Created on: 15 Mar 2014
     *      Author: Aadit
     */
    
    #ifndef MAIN_H_
    #define MAIN_H_
    
    struct userbase
    {
        char *username;
        char *password;
    };
    
    // return 2 if success
    #define CHECK_ERROR  4
    int check(int a,char *x[],struct userbase *u)
    {
        if(a == 2)
        {
            if(!strcmp(x[1],"start"))
            {
                u->username = "aadit";
                u->password = "password";
    
                return 2;
            }
            return CHECK_ERROR; // 4
        }
        else
            return 1;
    }
    
    
    #endif /* MAIN_H_ */
    
    For those who has not used assert function in c.
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Home Channels Search Login Register