// file: /data/courses/ece_1111/lectures/current/lecture_14/example.cc // // local include files // #include "example.h" // function: main // // This is a simple program that prints to the terminal. // int main(int argc, const char** argv) { // print the program name // fprintf(stdout, "program name: %s\n", argv[0]); fprintf(stdout, "second arg: %s\n", argv[1]); fprintf(stdout, "third arg: %s\n", argv[2]); float sum = atof(argv[2]); fprintf(stdout, "third arg as a number: %f\n", sum); // declare a character string // char* joe = (char*)"ece_111"; fprintf(stdout, "%s %s\n", "my character string =", joe); // declare a boolean value // bool b = true; bool bb = false; // sizeof // fprintf(stdout, "the size of b is %d bytes\n", sizeof(b)); unsigned char c = (unsigned char)257; fprintf(stdout, "c = %d, the number of bytes = %d\n", c, sizeof(c)); short int s = 32768; fprintf(stdout, "s = %d, the number of bytes = %d\n", s, sizeof(s)); int l = 99; fprintf(stdout, "value = %d, the number of bytes = %d\n", l, sizeof(l)); long ll = 99; fprintf(stdout, "value = %d, the number of bytes = %d\n", ll, sizeof(ll)); // unsigned char chr = 1; float x = atof(argv[1]); fprintf(stdout, "value = %f, the number of bytes = %d\n", x, sizeof(x)); double y = atof(argv[2]); fprintf(stdout, "value = %f, the number of bytes = %d\n", y, sizeof(y)); /* // demonstrate floats and the math library // float xxx = atof(argv[1]); fprintf(stdout, "x = %15.10f\n", xxx); float my_pi = M_PI; float my_sin = sin(my_pi); fprintf(stdout, "sin of %f = %f\n", my_pi, my_sin); // define our own constant // double xx = JOES_NUMBER; fprintf(stdout, "xx = %f\n", xx); fprintf(stdout, "xx = %e\n", xx); x = x / pow(10, 9); int sz_f = sizeof(float); int sz_d = sizeof(double); //fprintf(stdout, "the value of x is %f (%d %d)\n", x, sz_f, sz_d); double y = 27.2727272727; fprintf(stdout, "the value of y is %f\n", y); float v = 27.2727272727; fprintf(stdout, "the value of v is %f\n", v); /* float z = M_PI; //fprintf(stdout, "the value of z is %15.4e\n", z); //unsigned int i = atoi(argv[1]); //fprintf(stdout, "i = %f (%s)\n", i, argv[1]); // declare an unsigned char - one byte // //float x; //fprintf(stdout, "%fd: %f\n", x, x); unsigned char foo, goo, fsoso, j; //for (long i = 0; i < 257; i++) { //foo = i; //fprintf(stdout, "%d: %d\n", i, foo); // } // declare a signed character - ASCII // //char c; //for (long i = -128; i < 128; i++) { //c = i; //fprintf(stdout, "%d: %c (%d)\n", i, c, c); //} // declare a 16-bit integer // //short s; // unsigned short us; //for (long i = -32768; i < 32768; i++) { //s = i; //fprintf(stdout, "%d: %d (%d)\n", i, s, s); // } // declare an "int" integer // // int k; // unsigned int uk; // for (int i = -pow(2,31); i < pow(2,31); i++) { // k = i; // fprintf(stdout, "%d: %d (%d)\n", k, k, k); // } // declare long integer // // long l; // unsigned long ul; // for (long i = -2^63; i < 2^63 - 1; i++) { // s = i; // fprintf(stdout, "%d: %d (%d)\n", i, s, s); // } // declare a floating-point number // // float x = 27.00125; //fprintf(stdout, "x = %f\n", x); // declare a double precision floating-point number // // double y = 27.00125; //fprintf(stdout, "y = %f\n", y); */ // exit gracefully // return(0); }