Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Types conversion

Posted on 2000-05-12
19
Medium Priority
?
329 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
Independent Software Vendors: 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

610 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