q1: The variable
s
is a pointer to an array of characters, so you need to use the pointer type in the parameter field of the function.
q2. That is just a matter of choice, it is not essential to use
unsigned
.
q3. In this case it does not matter,
++counter
or
counter++
both do what is needed. You only need to be specific when you are capturing the value at the time that you use the increment operator.
q4. If you wish to use s1 as a pointer to something, then you must declare it as such:
char c1 = 'l'; char * s1 = "a string";
q5. The final character in a C character array is
'\0'
(i.e a zero byte) so that is the way to test if you have reached the end of the string.
See
Organization of the C Language Reference | Microsoft Docs[
^] for full details on the C language.
[edit]
When creating a 'string' in C you have two possibilities. but remember that there is no string type in C, they are just simple arrays. When you create a string it can be a local array or a pointer to literal:
char s1[] = "this is a local array";
char *s2 = "this is a literal";
Variable
s1
allocates space for the characters in the normal data space of the application. Variable
s2
creates a pointer in the normal data space, but creates the string literal separately. When accessing the data you may use either pointers, or array offsets. Although s1 is an array, its name is treated by the compiler as a pointer to the first character. So when calling the following function to do something with the data you can do :
void function(char *pszText)
{
while (*s1)
{
}
}
function(s1); function(s2); function(&s1[0]);
[/edit]