?
Solved

Types conversion

Posted on 2000-05-12
19
Medium Priority
?
328 Views
Last Modified: 2010-04-15
Hello:

I have one variable (char (*)(200)

I have a function with one argument (const unsigned short *)

How must I to call to the function with the variable?

Thanks
ORM =;-))
0
Comment
Question by:orueda
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
  • 2
  • +2
19 Comments
 
LVL 10

Expert Comment

by:rbr
ID: 2803921
First of all what is char(*) (200). Do you have a char pointer or an array of 200 characters.

Second what want you do with the conversion. A casting alone will do nothing.
0
 
LVL 10

Expert Comment

by:makerp
ID: 2803949
/* ATOF.C: This program shows how numbers stored
 * as strings can be converted to numeric values
 * using the atof, atoi, and atol functions.
 */

#include <stdlib.h>
#include <stdio.h>

void main( void )
{
   char *s; double x; int i; long l;

   s = "  -2309.12E-15";    /* Test of atof */
   x = atof( s );
   printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );

   s = "7.8912654773d210";  /* Test of atof */
   x = atof( s );
   printf( "atof test: ASCII string: %s\tfloat:  %e\n", s, x );

   s = "  -9885 pigs";      /* Test of atoi */
   i = atoi( s );
   printf( "atoi test: ASCII string: %s\t\tinteger: %d\n", s, i );

   s = "98854 dollars";     /* Test of atol */
   l = atol( s );
   printf( "atol test: ASCII string: %s\t\tlong: %ld\n", s, l );
}

convert it then pass it.
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2803999
by char(*)(200) you ment (char*)[200]

in a function prototype you should write
void func(char**str);

did i understand you right?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:orueda
ID: 2804233
Adjusted points from 100 to 200
0
 
LVL 1

Author Comment

by:orueda
ID: 2804234
makerp:
I don´t want to convert to numeric value

ntdragon:
the function is from API and I don't can to modify the function

the question is:
I have one string in a char * 200 and I want to use it with a function from API, the argument is PCWSTR (const unsigned short *, I think). How can I to do this?

do you undestand me?

Thanks
ORM =;-))
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804240
you will have to convert it. it wont convert the original value but give you a new variable thats a converted version of the original.

0
 
LVL 1

Author Comment

by:orueda
ID: 2804255
How? makerp
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804273

atoi returns an integer represntation of the string passed. it must be a valid string to be converted. "12" will return 12 but "dfdf12" will return 0

function1(&atoi(your_string_var);
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804274
i forgot the closing bracket

your_Api_call(&atoi(string_var))
0
 
LVL 1

Author Comment

by:orueda
ID: 2804296
How? makerp
0
 
LVL 1

Author Comment

by:orueda
ID: 2804304
How? makerp
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804309
give me the prototype for your API call
0
 
LVL 1

Author Comment

by:orueda
ID: 2804311
I don´t want to convert to numeric value. The value isn´t numeric!!!
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804322
post the full api delaration out of the help file etc....
0
 
LVL 1

Author Comment

by:orueda
ID: 2804388
Declaration:

HRESULT  AddOneCommand (
    DWORD dwID,
    PCWSTR pszCommand,
    PCWSTR pszDescription = NULL,
    PCWSTR pszCategory = NULL,
    DWORD dwFlags = 0,
    PVOID pAction = NULL,
    DWORD dwActionSize = NULL)

Example:

hRes = pCMenu->AddOneCommand(1, L"Open", L"Opens a message box", L"Window");

But I don´t want 'L"Open"' I want a variable (char * 200)!
0
 
LVL 10

Expert Comment

by:makerp
ID: 2804478
cant you do this

char buf[40];

strcpy(buf,"your string");

hRes = pCMenu->AddOneCommand(1, L buf, L"Opens a message box", L"Window");



0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2805404
i still don't understand
the char(*)(200)
it's:
(char*) str[200];
or
char str[200];
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 800 total points
ID: 2807111
It looks like you are using the UNICODE version of a AddOneCommand. If so, then why are you using char*, you should be using TCHARs or WCHARs.

But if you really need to convert from a char* to a WCHAR, you need to use the MultiByteToWideChar function (assuming str is a char*):

  int bufLen = (strlen(str) + 1) * sizeof(WCHAR);
  WCHAR* wstr = (WCHAR*)malloc(bufLen);
  MultiByteToWideChar(CP_ACP, 0, str, -1, wstr, bufLen);

 
0
 
LVL 1

Author Comment

by:orueda
ID: 2809857
Thanks thui
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question