Please someone who knows c for 100 years to explain to me what am I looking at here. Am I taking the right route to learning c as a career? WOW what is this I really would like to know what is going on here
#include <stdio.h>
#include <string.h>
int main() {
char *checkArr[1000] = {"This is very good",
"text that has been",
"put into a file for",
"the purposes of",
"being an example.", NULL};
int size2 = strlen(checkArr);
printf("Check Array size: %d\n", size2);
for (int i =0; i < strlen(checkArr); i++){
printf("%s\n", checkArr[i]);
}
char *checkArr2[1000] = {"This is very good",
"text that has been",
"put into a file for",
NULL,
NULL, NULL};
int size3 = strlen(checkArr2);
printf("Check Array size: %d\n", size3);
for (int i =0; i < strlen(checkArr2); i++){
printf("%s\n", checkArr2[i]);
}
for (int i =0; i < strlen(checkArr2); i++){
printf("%s\n", checkArr2[i]);
}
char *checkArr3[1000] = {"This is very good",
"text that has been",};
int size4 = strlen(checkArr3);
printf("Check Array size: %d\n", size4);
for (int i =0; i < strlen(checkArr3); i++){
printf("%s\n", checkArr3[i]);
}
char *checkArr4[1000] = {"This is very good",
"text that has been",
NULL,
NULL,
NULL, NULL};
int size5 = strlen(checkArr4);
printf("Check Array size: %d\n", size5);
for (int i =0; i < strlen(checkArr4); i++){
printf("%s\n", checkArr4[i]);
}
return 0;
}
Explain this below please, stdout
Check Array size: 5
This is very good
text that has been
put into a file for
the purposes of
being an example.
Check Array size: 5
This is very good
text that has been
put into a file for
(null)
(null)
This is very good
text that has been
put into a file for
(null)
(null)
Check Array size: 5
This is very good
text that has been
(null)
(null)
(null)
Check Array size: 5
This is very good
text that has been
(null)
(null)
(null)
How is this possible. How can all these arrays have the same size length???
strlenon an array of strings. Would not recommend it.strlento get the number of array elements. This doesn't compile. You are using thestrlenreturn value as the count of the number of array elements, so this won't work. Do:#define COUNTOF(_arr) (sizeof(_arr) / sizeof(_arr[0]))and replace all the (e.g.)strlen(checkArray)withCOUNTOF(checkArray)