Member • Mar 14, 2014
What is wrong in this code?
/* * main.c * * Created on: 13 Mar 2014 * Author: Aadit */ #includeWhat is wrong?#include #include #include #include #define PRINT_HELP printf("Help commands \n: start - TO START THE PROGRAM\version - VERSION OF PROGRAM\n") #define PROG_NAME(x) (printf("Current program running: %s.exe\n",x)) #define USAGE printf("Usage: For list of commands type help\n") #define PRINT_VERSION printf("Version : 1.0.0.0\n"); #define GET_NUMBER1(x) (scanf("%f",&x)) #define GET_NUMBER2(x) (scanf("%f",&x)) #define INPUT_NUMBERS printf("Input two numbers ,one for square root and one for square:\n") /* Number system */ struct Base { float num1,num2; }; int check(char a); void get_data(struct Base *b); int sq_root(float a); void calculation(float *a,float *b,struct Base *b_test); void check_arg(float,float,struct Base,char*[]); int main(int argc,char *argv[]) { struct Base base; float sq_root,sq; PROG_NAME(argv[0]); check_arg(sq,sq_root,base,argv[1]); if(argc<=1) { printf("Bye\n"); exit(0); } return 0; system("cls"); } int square(float a) { return (a*a); } int sq_root(float a) { return(sqrt(a)); } void get_data(struct Base *b) { // Get values GET_NUMBER1(b->num1);GET_NUMBER2(b->num2); } void calculation(float *a,float *b,struct Base *b_test) { *a = square(b_test->num1); // calculate square *b = sq_root(b_test->num2); // calculate square root // return multiple values using pointers } int check(char a) { if(a == 's') return 0; // show square result else return 2; // show square_root } void check_arg(float a,float b,struct Base b1,char *c[]) { if(!strcmp(c[1],"start")) { system("cls"); INPUT_NUMBERS; get_data(&b); calculation(&a,&b,&b); } else if(strcmp(c[1],"version")) { PRINT_VERSION; } else if(strcmp(c[1],"help")) { PRINT_HELP; } else if(!strcmp(c[1],"usage")) USAGE; }
I think there is an error in command line arguments.