A simple program that uses assert() function.
MAIN.C
/* * main.c * * Created on: 15 Mar 2014 * Author: Aadit */ #includeMAIN.H#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 * * 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
You are reading an archived discussion.
Related Posts
Stumbled upon this totally addictive game. Trust me, it does not look addictive but I bet a few moves into the game and you would have that 'never give up'...
What is the difference between isd 1420 and isd 1820..??
Can we replace isd 1420 with isd 1820..??
PLz help me out with this query
chetan : My email id...
may i know about some sensible steering systems that will alert when the driver get collapsed
any motor company implemented yet
A human wearable robot has been developed by Italian Engineers. This robot consist of parts similar to that of human body and are designed to fit a human being perfectly....
Hey everyone.
I own Sony Ericsson Ray (ST18i) with android version 4.0.4. Earlier it was android version 2.0 which I upgraded to the version 4. Due to it, my phone...