Do you understand how str gets passed to scanf here, and how the result gets back into the local array 'str'?
Code:
int main(void)
{
char str[5];
printf("Enter security code: ");
scanf("%4s", str);
printf("Code=%s\n",str);
return 0;
}
This is no different.
Code:
void security(char []);
int main(void)
{
char str[5];
security(str);
printf("Code=%s\n",str);
return 0;
}
void security(char str[])
{
printf("Enter security code: ");
scanf("%4s", str);
}
There is only ONE array, and that's the one declared in main.
Every other function down the chain is just dealing with a pointer to that array.
If you really want to emphasis the "pointer" side of things, you could equally have written.
Code:
void security(char *); // absolutely no difference with char[]
int main(void)
{
char str[5];
security(str);
printf("Code=%s\n",str);
return 0;
}
// The name you use here has NO relation to the name(s)
// of any parameters you choose to call it with
void security(char *word)
{
printf("Enter security code: ");
scanf("%4s", word);
}