Solved

Types conversion

Posted on 2000-05-12
19
321 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

758 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

17 Experts available now in Live!

Get 1:1 Help Now