473,803 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

char *query[]

Why does query[1] = www ?

int
main(void)
{
char *user="www";
char *password="";
char *database="www" ;
char *query[]={"SHOW DATABASES;"};
db(user,passwor d,database,quer y);
}

(gdb) next
12 char *query[]={"SHOW DATABASES;"};
(gdb) next
13 db(user,passwor d,database,quer y);
(gdb) print query
$5 = {0x400e25 "SHOW DATABASES;"}
(gdb) print query[0]
$6 = 0x400e25 "SHOW DATABASES;"
(gdb) print query[1]
$7 = 0x400e20 "www"
(gdb) print query[2]
$8 = 0x400e24 ""
(gdb) print query[3]
$9 = 0x400e20 "www"
(gdb) print query[4]
$10 = 0x0
(gdb)

source
----------
http://dfo.svn.sourceforge.net/viewv...74&view=markup

Jul 15 '07
14 2135
On Sun, 15 Jul 2007 16:57:56 -0000, gert <ge**********@g mail.com>
wrote:
>On Jul 15, 6:47 pm, gert <gert.cuyk...@g mail.comwrote:
>There goes my carefully thought out NASA for loop :(

for(q=0;s=quer y[q];q++)

Guess the only solution would be using a max value then ?

o wait a minute what about

char **query = {"SHOW DATABASES;", 0x0 };
Did you try this? Did you not get a compiler diagnostic complaining
about too many initializers?
>
>(gdb) print query[4]
$10 = 0x0

How can i force a 0x0 boundary ?
First tell us what a 0x0 boundary is. Do you mean where the address
is always a multiple of 0x10? If so, there is no way to do so
portably.
Remove del for email
Jul 16 '07 #11
On Jul 15, 9:20 pm, j...@toerring.d e (Jens Thoms Toerring) wrote:
gert <gert.cuyk...@g mail.comwrote:
On Jul 15, 6:47 pm, gert <gert.cuyk...@g mail.comwrote:
There goes my carefully thought out NASA for loop :(
for(q=0;s=query[q];q++)
Guess the only solution would be using a max value then ?
o wait a minute what about
char **query = {"SHOW DATABASES;", 0x0 };

You should use NULL instead of 0x0 - NULL is null pointer
while 0x0 is an integer constant (and the representation
of a null pointer isn't necessarily all bits 0 as in 0x0).

Now you can use your loop

for (q=0;s=query[q];q++ )

since s will be set to NULL for q==1 amd thus the loop will
end without accessing a non-existing array element.
(gdb) print query[4]
$10 = 0x0
How can i force a 0x0 boundary ?

I don't know what you mean with "0x0 boundary", but you
simply aren't allowed to ty to access elements past the
end of the array and you must find a way to avoid that,
like the one you already came up with, i.e. by having a
NULL pointer as the last element that you can test for.

Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.d e
\______________ ____________ http://toerring.de
Why not to use?
char *elem;
int i;
....
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}
It is more straightforward and simple solution, I think.

crox

Jul 16 '07 #12
crox <cr*****@gmail. comwrites:
On Jul 15, 9:20 pm, j...@toerring.d e (Jens Thoms Toerring) wrote:
>gert <gert.cuyk...@g mail.comwrote:
On Jul 15, 6:47 pm, gert <gert.cuyk...@g mail.comwrote:
There goes my carefully thought out NASA for loop :(
for(q=0;s=query[q];q++)
Guess the only solution would be using a max value then ?
o wait a minute what about
char **query = {"SHOW DATABASES;", 0x0 };
<snip>
>--
\ Jens Thoms Toerring ___ j...@toerring.d e
\______________ ____________ http://toerring.de
Don't quote sigs.
Why not to use?
char *elem;
int i;
...
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}
It is more straightforward and simple solution, I think.
Did you mean 'i < sizeof(query)/sizeof(*query)' perhaps? I am not sure
because of the mysterious 'char *elem;' declaration.

To the OP: if you go this route, take the terminating NULL (0x0) out
of the array and you must, of course, declare 'query' as an array:

char *query[] = { "one", "two" };

--
Ben.
Jul 16 '07 #13
On Jul 16, 3:16 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
crox <craz...@gmail. comwrites:
On Jul 15, 9:20 pm, j...@toerring.d e (Jens Thoms Toerring) wrote:
gert <gert.cuyk...@g mail.comwrote:
On Jul 15, 6:47 pm, gert <gert.cuyk...@g mail.comwrote:
There goes my carefully thought out NASA for loop :(
for(q=0;s=query[q];q++)
Guess the only solution would be using a max value then ?
o wait a minute what about
char **query = {"SHOW DATABASES;", 0x0 };
<snip>
--
\ Jens Thoms Toerring ___ j...@toerring.d e
\______________ ____________ http://toerring.de

Don't quote sigs.
Why not to use?
char *elem;
int i;
...
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}
It is more straightforward and simple solution, I think.

Did you mean 'i < sizeof(query)/sizeof(*query)' perhaps? I am not sure
because of the mysterious 'char *elem;' declaration.

To the OP: if you go this route, take the terminating NULL (0x0) out
of the array and you must, of course, declare 'query' as an array:

char *query[] = { "one", "two" };

--
Ben.
Oops, sorry I mean:
char *query[] = {"Do 1", "Do 2"};
int i;
...
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}

Jul 17 '07 #14
crox wrote:
On Jul 16, 3:16 pm, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
crox <craz...@gmail. comwrites:
On Jul 15, 9:20 pm, j...@toerring.d e (Jens Thoms Toerring) wrote:
>gert <gert.cuyk...@g mail.comwrote:
On Jul 15, 6:47 pm, gert <gert.cuyk...@g mail.comwrote:
There goes my carefully thought out NASA for loop :(
for(q=0;s=query[q];q++)
Guess the only solution would be using a max value then ?
o wait a minute what about
char **query = {"SHOW DATABASES;", 0x0 };
<snip>
>--
> \ Jens Thoms Toerring ___ j...@toerring.d e
> \______________ ____________ http://toerring.de
Don't quote sigs.
Why not to use?
char *elem;
int i;
...
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}
It is more straightforward and simple solution, I think.
Did you mean 'i < sizeof(query)/sizeof(*query)' perhaps? I am not sure
because of the mysterious 'char *elem;' declaration.

To the OP: if you go this route, take the terminating NULL (0x0) out
of the array and you must, of course, declare 'query' as an array:

char *query[] = { "one", "two" };

--
Ben.
When will you do us the favour of not quoting sigs?
Oops, sorry I mean:
char *query[] = {"Do 1", "Do 2"};
int i;
...
for(i=0; i < sizeof(query); i++) {
do_something_wi th(query[i]);
}
This is wrong. sizeof(query) will return the size, in bytes of the
array named query. You want the number of elements in the array. For
that, you should do:

sizeof query / sizeof query[0];

This will yield two.

Jul 17 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2720
by: david | last post by:
Hello, Is the code below correct ? I always get an seg fault on execution and the debugger points to c_str() ? Basically i want to convert the value std::string to char * within the iterator loop. ..... {
1
2961
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a problem: select * from dbo.VwTransaction where
2
4199
by: Jon Lapham | last post by:
I have a table that stores TEXT information. I need query this table to find *exact* matches to the TEXT... no regular expressions, no LIKE queries, etc. The TEXT could be from 1 to 10000+ characters in length, quite variable. If it matters, the TEXT may contain UNICODE characters... Example: CREATE TABLE a (id SERIAL, thetext TEXT); SELECT id FROM a WHERE thetext='Some other text'; One way I thought to optimize this process would...
5
6793
by: tienlx | last post by:
Hi all, I'm have a problem that i don't know how to convert object to char in C# . Does anybody know ? Thanks.
7
4950
by: jaawaad | last post by:
I have a text field in a table that contains number along with chars. Is there a way i can write a query to show all the fields that contains just Numbers or Char in a field?? TBALE Example COL1 : COL2(nvarchar) --------------------------- 100 345G01 200 123456789
2
2217
by: Wayne Sepega | last post by:
I'm receiving the above error from time to time with one of our web pages. What would cause this? Thanks Wayne The following is the stacktrace from the exception: System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---System.FormatException: Invalid length for a Base-64 char array. at
0
1354
by: Medhatithi | last post by:
I have a table whose indexed column is a char(16) field. I am giving the schema. CREATE TABLE Emp(Empno char(16), Ename varchar(25), Salary number(10,2),......) Now, there is an index on the Empno field. Now, inside a stored procedure, I am executing a statement select Name=Ename from Emp where Empno=@eno This @eno is varchar(25). So, SQL Server would do the implicit...
2
7044
by: iritchie | last post by:
*(Apologies, I posted this in the SQL Server forum first) Hello all, I am trying to write a query which breaks down a single address field into individual fields, with char(10) or a carriage return as the delimiter. "empltable" is the table I am using, and "address" is the field I am looking to split. So far I have managed to:
1
2828
by: rottmanj | last post by:
I have written a class that manages all the database connection information/methods I need to connect to a database and query off of it. In order to make my application dynamic so that it can read from multiple tables I setup 4 variables that I will populate at another time. These variables hold the data for database I want to connect to. Currently when I run the code, I end up with this as the output. test �y������� DB connection...
0
9699
marktang
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...
0
9562
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,...
0
10542
Oralloy
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...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6840
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();...
0
5496
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...
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.