Solved

Types conversion

Posted on 2000-05-12
19
325 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

856 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