I've got a variable file of type char*, and am trying to iterate through a for loop by doing the following:
Code:
int idx;
for (idx=0; file[idx] != '\0'; idx++) {
//do some stuff
}
The file[idx] part of the stop condition results in the error Segmentation fault (core dumped). I believe that I am not quite understanding something related to indexing and character pointers. Could someone shed some light on this for me? Thanks!
I notice that couple of test lines preceeding this code:
Code:
printf("%c\n", file[0]);
printf("%c\n", file[0]);
do seem to be giving expected results. How can i translate file[idx] into a character that i can use in my stop condition?