Suppose I have the following function:
void doSomething(cha r** array, int size);
Normally, I would call the function with an array of, say, 3
elements...
char* strs[] = { "str1","str2"," str3" };
doSomething(str s, 3);
That works fine. But if I want to pass it only one char*, I would
think this would work....
char* str = "str1";
doSomething(&st r, 1);
It compiles with a warning about incompatible pointer types, and
needless to say it doesn't behave as I expected. "str1" does not get
passed into the function. What am I doing wrong? How can I pass a
single char* into the function?
Nov 15 '05
12 3062
Primarily what you need to do is to avoid the warning you need to
typecast
by doing doSomething((ch ar **)&str,1);
So let's say your function is
void doSomething(cha r** s, int size)
{
printf("%s\n",* s);
}
This needs to be done because you are not printing s[0], instead are
trying to print address of s[0];
Remember this is a double pointer.
> Primarily what you need to do is to avoid the warning you need to typecast by doing doSomething((ch ar **)&str,1);
I'm not sure I'm understanding why you would have to absolutely try to
hush the compiler. Warnings are there for a good reason, most of the time.
The only thing we need to know is "is this warning announcing something
that was unexpected ?"... well, IMO at least :)
--
"Je deteste les ordinateurs : ils font toujours ce que je dis, jamais ce
que je veux !"
"The obvious mathematical breakthrough would be development of an easy
way to factor large prime numbers." (Bill Gates, The Road Ahead)
Thanks for all the feedback! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Francis Bell |
last post by:
Hello,
I've got a program that is reading in a data file of 25 lines. Here is
an example of the first two lines:
sp/spinnerbait/AAA Lures/Mad Phil/silver/bass/1/1
f/floating minnow/AAA Lures/Skinny Minney/green/bass/0/0/0
In my program, I need to read in each line, BUT, I need to build a
different object based upon the characters in the first field. So, I
|
by: JKop |
last post by:
Why isn't:
int main(int argc, char* argv) { /* ... */ }
as:
int main(int argc, const char* argv)
|
by: Johnathan Doe |
last post by:
Why is is necessary to write a function that allocates memory for, or
changes, a pointer to a char array using char** instead of char*?
E.g.
void modify_string( char** string )
{
if( string == NULL )
return;
|
by: jab3 |
last post by:
(again :))
Hello everyone.
I'll ask this even at risk of being accused of not researching adequately.
My question (before longer reasoning) is: How does declaring (or defining,
whatever) a variable **var make it an array of pointers?
I realize that 'char **var' is a pointer to a pointer of type char (I hope).
And I realize that with var, var is actually a memory address (or at
|
by: fernandez.dan |
last post by:
My question is about if I should return char* or have a char* as an
argument. My basic premise for this function is to return a char*
buffer and the size of the buffer to the caller. I know that each of
the following works but Stylistic which would be the better approach.
Here are my two examples:
char* GetBuffer(long* size);
or
| |
by: poison.summer |
last post by:
For instance, I'd like to use unsigned char as an 8-bit integer.
Can I use like
unsigned char a=0;
a++
Thanks a lot!
|
by: ZMan |
last post by:
The following code won't compile with gcc version 3.4.2
(mingw-special).
How come?
Error: cannot convert `char (*)' to `char**'
/**********************************************************/
#include <cstdio>
#define MAX_WORD_LEN 80
#define MAX_SIZE 1000
|
by: Francine.Neary |
last post by:
I've been reflecting on these two types of pointer. As far as I can
glean from books, void * and char * are functionally equivalent: the
key property of both is that they are pointers that can be faithfully
cast to any other pointer type.
The only difference seems to be that it is legal to perform arithmetic
on a char *, but not on a void *.
So if a char * really is just a more functional void *, why would
anyone ever use a void * in...
|
by: Siol |
last post by:
I'm trying to call a dll function from C# which has the following form:
int some_function(int count, char **arg1, char **arg2)
Which parameter type I need to use in C# for C++ char** type? I tried
byte (array of byte) but I get error "There is no marshaling support
for nested arrays."
regards
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |