// file: lecture_12/example.cc // // a simple program to play around with data types, including // pointers and arrays // // system include files // #include "example.h" // function: main // // main program starts here // int main(int argc, char** argv) { FILE* fp = fopen(argv[1], "r"); if (fp == (FILE*)NULL) { fprintf(stderr, "Ouch - an error has occurred\n"); return -1; } // char* x = "Joe"; // char* y = "Mary"; // char* z = strcat(x,y); char* q = (char*)"Friday"; fprintf(stdout, "... %s\n", (char*)&q); /* fprintf(stdout, "program name: %s\n", argv[0]); char* x[3]; x[0] = (char*)"Joe"; x[1] = new char[2]; x[1][0] = 'a'; x[1][1] = (char)NULL; x[2] = new char[strlen(argv[0]) + 1]; strcpy(x[2], argv[0]); fprintf(stdout, "value = %c (%s) (%s)\n", x[1][0], x[1], x[2]); /* float sum = (float)27.2727; fprintf(stdout, "sum = %f (%ld)\n", sum, &sum); float* ptr_sum = ∑ // fprintf(stdout, "sum = %f (%ld) (%ld)\n", *pp_sum, ptr_sum, &ptr_sum); // char str[4] = "Joe"; char* str = (char*)"Joe"; char* pstr = str; long i = 0; while (*pstr != (char)NULL) { fprintf(stdout, "%d: %c\n", i++, *pstr++); char* foo = str + pstr; } */ // exit gracefully // return(0); }