// 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; } short int buf[99]; long nitems_read = fread(buf, sizeof(short int), 99, fp); fprintf(stdout, "number of items read = %d\n", nitems_read); fclose(fp); */ /* char* x = "Joe"; char* y = "Mary"; char* z = strcat(x,y); */ /* char* q = (char*)"Friday"; fprintf(stdout, "... %s\n", q); */ /* for (long i = 0; i < argc; i++) { fprintf(stdout, "arg[%d] = %s\n", i, argv[i]); } */ char* ptr = (char*)"Joe"; /* while (*ptr != (char)NULL) { fprintf(stdout, "value = %c\n", *ptr); ptr++; } */ long len = strlen(ptr); fprintf(stdout, "len = %d\n", len); char* pp = ptr; for (long i = 0; i < len; i++) { fprintf(stdout, "ptr[%d] = %c\n", i, *pp); pp++; } /* for (; *ptr != (char)NULL; ptr++) { fprintf(stdout, "value = %c\n", *ptr); } */ /* 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); }