473,382 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

a question about a string

QQ
I have a string

the length is 0. I got it from strlen(TE);
however, if I use

if(TE!=NULL)
{

}

it always goes to this loop.

Does strlen(TE)=0 mean TE=NULL?

Thanks a lot!

Feb 21 '06 #1
11 1470
QQ wrote:
I have a string

the length is 0. I got it from strlen(TE);
however, if I use

if(TE!=NULL)
{

}

it always goes to this loop.

Does strlen(TE)=0 mean TE=NULL?

No, but it means that *TE == 0 (or, if you prefer, '\0').

HTH,
--ag

--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Feb 21 '06 #2
QQ
what's the different between
TE==NULL and
*TE==0
?

Feb 21 '06 #3
On 2006-02-21, QQ <ju****@yahoo.com> wrote:
what's the different between
TE==NULL and
*TE==0


The latter sets the first character to zero, in effect making the string
empty "".
Feb 21 '06 #4

QQ wrote:
what's the different between
TE==NULL and
*TE==0


Please quote some context when replying. Even if you're replying to
your own post. Also, read: http://cfaj.freeshell.org/google/
If people see this post they won't know what TE is and nobody has to
read your older posts.
If *TE==0 (*TE=='\0') the first character of your string contains the
string
termination character, i.e. empty string (strlen(TE)==0).
If TE==NULL it means you have a pointer to a character that's
initialized to
NULL. You can't store anything into it. If you make it point to some
area in
memory that you are allowed to use (you allocated space for it) then
you can
use it to store characters.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)

Feb 21 '06 #5
QQ wrote:

what's the different between
TE==NULL and
*TE==0
?


TN == NULL
TN is a null pointer, it doesn't point to anything.
*TN is a constraint violation.

*TS==0
TS is a string pointer.
TS points to a byte that has a value of zero.

--
pete
Feb 21 '06 #6
QQ wrote:
what's the different between
TE==NULL and
*TE==0


if (TE == NULL) /* if TE points "to nowhere" */

if (*TE == 0) /* if the thing TE points to is 0 */

newbie example, trying to explain with a bit of fun mixed-in:

point your finger to any number (read vertically) in the list below.

0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4

.... Let's say you pointed to the number 18 and call your finger TE, so

*TE == 0 /* evaluates to false, because *TE == 18 */
TE == NULL /* evaluates to false, because TE is pointing to
somewhere relevant */

.... now cut your finger off (or, better, close your hand into a fist)

TE == NULL /* evaluates to true now; your finger isn't pointing to
anywhere */
/* *TE == 0 */ /* you can't do this now -- if the finger isn't
pointing to somewhere specific, you can't check
the value of what it points to */

.... now, assuming you opted to close your hand, point your finger to the
number 0 in the list

TE == NULL /* evaluates to false again */
*TE == 0 /* evaluates to true */

move your finger 26 positions to the right (TE = TE + 26;)
Q: where does it point to?
A: it points to somewhere outside the boundaries of the list and (if I
am not wrong) you have demons oozing out of your nostrils at this
moment :)

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Feb 21 '06 #7
On 2006-02-21, pete <pf*****@mindspring.com> wrote:
QQ wrote:

what's the different between
TE==NULL and
*TE==0
?


TN == NULL
TN is a null pointer, it doesn't point to anything.
*TN is a constraint violation.


If by constraint violation you mean undefined behavior. But i think he
meant one or the other, not both in turn
Feb 22 '06 #8
Jordan Abel wrote:
On 2006-02-21, QQ <ju****@yahoo.com> wrote:
what's the different between
TE==NULL and
*TE==0

The latter sets the first character to zero, in effect making the string
empty "".


Correction - The latter checks if the value in the location pointed to
by TE is zero or not.
Feb 22 '06 #9
QQ wrote:

what's the different between
TE==NULL and
*TE==0
?


The first (TE == NULL) says "is TE a NULL pointer?"

The second (*TE == 0) says "does TE point to a zero?"

Warning! Bad analogy coming up.

Suppose TE is a key holder. "*TE==0" would be "the box that the key opens
is empty" whereas "TE==NULL" would be "you have no key".

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>
Feb 22 '06 #10
On 21 Feb 2006 12:30:28 -0800, in comp.lang.c , "QQ"
<ju****@yahoo.com> wrote:
I have a string

the length is 0. I got it from strlen(TE);
however, if I use

if(TE!=NULL)
{

}

it always goes to this loop.
Of course it does - you're testing wether the pointer is NULL, not
whether its contents are of zero size.
Does strlen(TE)=0 mean TE=NULL?


No, its a pointer and can point to no bytes, but still be a pointer.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Feb 22 '06 #11
On 2006-02-21, Jordan Abel <ra*******@gmail.com> wrote:
On 2006-02-21, QQ <ju****@yahoo.com> wrote:
what's the different between
TE==NULL and
*TE==0


The latter sets the first character to zero, in effect making the string
empty "".


Slight misread there I think :-;

It checks if the character pointed to by TE have a value of 0.

--
Remove evomer to reply
Feb 22 '06 #12

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

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
11
by: kazack | last post by:
I am under the the impression that a variable is what is stored in a memory address and a pointer is the memory address of the variable? I was looking to use a function that does not return a...
1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
9
by: Alvin Bruney | last post by:
The more knowledgable I get about this .net world, the more questions I have. ..NET uses pass by reference for all objects....uhhh I mean pass by value. (Couldn't resist this jab) Consider a...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
14
by: key9 | last post by:
Hi All On coding , I think I need some basic help about how to write member function . I've readed the FAQ, but I am still confuse about it when coding(reference / pointer /instance) , so I...
4
by: Steve | last post by:
I have read a couple articles online, read my Jesse Liberty book but I am still confused as to just what the best practices are for using exceptions. I keep changing how I'm working with them and...
15
by: Lighter | last post by:
I find a BIG bug of VS 2005 about string class! #include <iostream> #include <string> using namespace std; string GetStr() { return string("Hello");
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.