We took a quick look at
fopen
to write
files and talked about the different kinds of errors that can be generated
when attempting to read or write a file.
Look at the following code segment found in arrayPtr.c
char *wordArray[MAX_WORDS]; /* compile-time array of char* */ char **wordArray2; /* pointer to char* */ char matrix[MAX_WORDS][30]; wordArray2 = (char**)malloc(MAX_WORDS * sizeof(char*)); /* wordArray2 is now a MAX_WORDS-size array of char*'s */
AND
We spent some time passing various arguments to the different array functions and, in particular, talked about the warning generated by the call of theprintMatrix
routine. We demonstrated how the correct prototype isvoid printMatrix(char arr[][30]);
orprintMatrix(char (*arr)[30]);
.
Here are some small programs that illustrate common uses of pointer arithmetic:
In ptrCast.c we mix casting with pointer arithmetic to do something funky...