Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am trying to pass a char value to a function whose parameter is a character pointer. But during the execution the program terminates abnormally but if i pass a string value say "Hello World" it works fine. Below is the function definition and pseudo code FYI.

int MyFunc( int iParam1, TCHAR * pParam );


now in main function i m calling the function this way.

C#
int main()
{
  MyFunc( 1, 2, 'C' );
  return 0;
}



Am i passing the char value properly or do i need to follow a different standard.
I am doing this through C on windows. Please correct me if I am wrong.
Posted

well you're passing 3 arguments while MyFunc only accepts 2, so we throw away the 2.

the MyFunc expects second argument expects a pointer to a TCHAR. You can do that in multiple ways here are some examples
C++
TCHAR ch = 'C';
MyFunc(1, &ch);

TCHAR* str = "C";
MyFunc(1, str);


This might be of interest
Pointers Usage in C++: Beginners to Advanced[^]
 
Share this answer
 
in MyFunc you must check your char pointer to don't be null

and then debug your program to find who call your function with null input argument.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900