Reputation: 1
I want to pass an array of characters i.e. a String in c
int main()
{
const char c[]="Joseph";
TestWord(&c,&c);
return 0;
}
int TestWord(char tiles[], char word[])
{
return tiles;
}
Upvotes: 0
Views: 66
Reputation: 1089
you could pass a string(character array) in C in many ways. This code passes the string a to the function PRINT. Note that in this method the base address of the array is sent to the function.
#include<stdio.h>
void PRINT(char b[])
{
printf("%s",b);
}
int main()
{
char a[]="hello";
PRINT(a);
return 0;
}
Upvotes: 1
Reputation: 674
#include <stdio.h>
char *TestWord(char tiles[], char word[]);
int main()
{
char c[]="Joseph";
char r;
r = *TestWord(c,c);
return 0;
}
char *TestWord(char tiles[], char word[])
{
return tiles;
}
You pass through the arrays without the &
as arrays don't need those, as they are already somewhat like pointers, just like how you would scanf
an array without the &
symbol.
Don't forget that if you are returning tiles
that you should save that in a variable.
Upvotes: 1