#include #include #include #include //EE 312 class code //command line arguments //2-D array of characters as array of strings //simple malloc statement int main(int argc, char *argv[]) { printf("Hello, World!\n"); printf("change2\n"); for (int i = 0; i < argc; i++) printf("%d %s\n", i, argv[i]); printf("------------\n\n"); char *stuff[10]; int numRows = 3; int numCols = 5; stuff[0] = "agvnf"; stuff[1] = "jfjQl"; stuff[2] = "sdaf6"; for (int i = 0; i < numRows; i++) printf("%d %s\n", i, stuff[i]); bool found = false; int row = 0; int col = 0; while (!found && row < numRows) { col = 0; while (!found && col < numCols) { if (stuff[row][col] == 'Q') { found = true; } else col++; } if (!found) row++; } if (found) printf("found at %d %d\n", row, col); else printf("not found\n"); printf("------------\n\n"); for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) printf("%c", stuff[i][j]); printf("\n"); } printf("------------\n\n"); char *foo; foo = (char*) malloc(12 * sizeof(char)); //allocate 12 bytes of memory and cast to char * strcpy(foo,"hey there ?"); printf ("%s\n", foo); stuff[0] = foo; printf("%s\n", stuff[0]); if (foo != NULL) free(foo); //give back the memory printf("------------\n\n"); return 0; }