// file: /data/courses/ece_1111/lectures/current/lecture_04/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) { // define an integer // long i = 27; int j = 9; // formatted I/O - different format specifications // printf("easy: the value of i is %7d\n", i); printf("easy: the value of i is %10d\n", i); printf("easy: the value of i is %15d\n", i); fprintf(stdout, "hard: the value of i is %7d\n", i); // define a floating-point number // float sum = 27.2727272727; fprintf(stdout, "the value of sum is %f\n", sum); fprintf(stdout, "the value of sum is %10.4f\n", sum); // doing math 'inline' // fprintf(stdout, "the value of sum is %f\n", sum + 999); fprintf(stdout, "the value of sum is %10.2f\n", (float)1.0); fprintf(stdout, "the value of sum is %10.2f\n", (float)999); fprintf(stdout, "the value of sum is %10.2f\n", sum); fprintf(stdout, "the value of sum is %15.4e\n", sum); fprintf(stdout, "i = %d, sum = %f\n", i, sum); fprintf(stdout, "i (%d), sum = (%f)\n", i, sum); fprintf(stdout, "********\n"); fprintf(stdout, "%s [%s]\n", "our first string", "today is Wednesday"); fprintf(stdout, "[%20.20s]\n", "1234567890"); fprintf(stdout, "[%20.20s]\n", "123"); fprintf(stdout, "[%.20s] [%.20s]\n", "1234567890", "123"); fprintf(stdout, "[%.20s]\n", "123"); fprintf(stdout, "[%s]\n", "1234567890"); fprintf(stdout, "hello world\n"); fprintf(stdout, "hello Joe\n"); // more advanced print using pointers // const char* ptr = "My name is Joe"; fprintf(stdout, "%s\n", ptr); // command line arguments // fprintf(stdout, "number of arguments = %d\n", argc); fprintf(stdout, "first command line argument: [%s]\n", argv[0]); fprintf(stdout, "second command line argument: [%s]\n", argv[1]); fprintf(stdout, "third command line argument: [%s]\n", argv[2]); // exit gracefully // return(0); }