Solved

Types conversion

Posted on 2000-05-12
19
322 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
  • 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
 
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 200 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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
outside company writing a dll in c/c++, I want to call it from C# 2 66
Passing a array as parameter - C 2 84
Problem to show menu 5 87
Problem to save 10 148
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…
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…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now