1-the expression "const char *responses[]"...what is the * doing there?!
Code:
char string_1[] = "This string can be modified";
// The above declares an array of characters - a string in 'C' is an array
// of characters that is terminated with a null character '\0'
const char *string_2 = "This string cannot be modified";
// The above line declares a character pointer that points to the memory location
// where the beginning of the string resides. When a string is declared this way,
// it cannot be modified as it can be when declared as a character array (above).
const char *responses[] = {
"Very good!",
"Excellent!",
"Nice Work!",
"Keep up the good work!"
};
// The above lines declare an array of character pointers, which is an array
// of strings, each string like the one in the previous example.
// Note that when declaring a character pointer, the string must be defined immediately.
2- why did you use %s in printf function instead of %c?!
%c will print a single character. %s will print a string (an array of characters terminated with a null character '\0').
Code:
char string_4[6] = "Hello"; // contains six characters: 'H' 'e' 'l' 'l' 'o' '\0'
int i;
// print a string character by character
for(i=0; i<6; i++)
printf("%c",string_4[i]);
// print a string all in one go
printf("%s",string_4); // "string_4" behaves like a pointer to the first element, string_4[0]
3- where, or how did u called the function "correct"?
This function can be called from any other function, same as all functions.
Code:
#include <stdio.h>
#include <stdlib.h>
// "correct()" function defined here
int main(void)
{
correct();
return 0;
}