0

Basically I am totally confused on how to pass a char, which is given by the user, and then store it and pass it to another function by reference.

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

pass it the same as anything else

void foo(char *c)
{

}

int main()
{
   char c = 'A'
   foo(&c);
}

So if its a user input then it would look something like

void foo(char *c)
{

}
int main()
{
      char b;
      printf("Enter a character: ");
      scanf("%c", &b); 
      foo(&b);
}
0

If you know the answer in line 9 what makes you think it would be any different on line 10? Afterall, both lines 9 and 10 are passing the char variable by reference to the functions.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.