473,396 Members | 2,004 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,396 software developers and data experts.

strlen + terminating null character

Hi all, a simple question, please look this code below:

char acName[]="Claudio" // My name
unsigned int uiLen;

uiLen=strlen(acName);

printf("Lenght of acName [%d]",uiLen);

printf("Display acName[iLenLenght of acName [%d]",uiLen);

printf("Lenght of acName [%d]",uiLen);

Nov 14 '05 #1
5 1326
lasek <cl**************@acrm.it> spoke thus:
char acName[]="Claudio" // My name
unsigned int uiLen; uiLen=strlen(acName); printf("Lenght of acName [%d]",uiLen); printf("Display acName[iLenLenght of acName [%d]",uiLen); printf("Lenght of acName [%d]",uiLen);


What's the question? All three printf's print the same number, which
is 7.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
lasek wrote:

Hi all, a simple question, please look this code below:

char acName[]="Claudio" // My name
unsigned int uiLen;

uiLen=strlen(acName);
printf("Lenght of acName [%d]",uiLen);
printf("Display acName[iLenLenght of acName [%d]",uiLen);
printf("Lenght of acName [%d]",uiLen);


So, what is the question? Length is misspelled. The code is
incomplete and won't compile, but seems reasonable, apart from the
use of // comments (which are bad in usenet because of line wrap,
and invalid if you don't have a C99 compiler, which most don't).
You are also allowed to use blanks around such tokens as = or after
a comma. They don't cost much, and there is no shortage nor
environmental price.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #3
"lasek" <cl**************@acrm.it> writes:
Hi all, a simple question, please look this code below:

char acName[]="Claudio" // My name
unsigned int uiLen;

uiLen=strlen(acName);

printf("Lenght of acName [%d]",uiLen);

printf("Display acName[iLenLenght of acName [%d]",uiLen);

printf("Lenght of acName [%d]",uiLen);


In addition to the comments provided by others, you should use "%u" to
print an unsigned int, not "%d".

It looks like you meant to say more than you did. Say it, and we'll
respond.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #4
Keith Thompson <ks***@mib.org> spoke thus:
It looks like you meant to say more than you did. Say it, and we'll
respond.


It turns out he did, in his next post, but none of us noticed it
before responding to this one. Oh well.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #5
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
Keith Thompson <ks***@mib.org> spoke thus:
It looks like you meant to say more than you did. Say it, and we'll
respond.


It turns out he did, in his next post, but none of us noticed it
before responding to this one. Oh well.


Right, because he started a new thread.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6

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

Similar topics

45
by: Matt Parkins | last post by:
Hi, (I realise this probably isn't precisely the right group for this - could someone direct me to the appropriate group to post this question? - thanks !) I'm using Visual C++ 2005 Express...
21
by: sugaray | last post by:
hi, it just came up my mind that since we can get the length of any given string literal S with 'sizeof S-1', so, what's the merit of library function strlen()'s existence ? thanx in advance for...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
8
by: lasek | last post by:
Hi all, a simple question, look at this code below: char acName="Claudio"; unsigned int uiLen; uiLen=strlen(acName); printf("Length of acName variable %u",uiLen); //uiLen >>>> 7
66
by: roy | last post by:
Hi, I was wondering how strlen is implemented. What if the input string doesn't have a null terminator, namely the '\0'? Thanks a lot Roy
83
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
2
by: danielesalatti | last post by:
Hello!! I'm studying c++ and I'm trying to get a little piece of code working, but I'm getting a segfault with strlen here: void tabhash::set (url *U) { uint hash = U->hashCode(); char* url =...
44
by: sam_cit | last post by:
Hi Everyone, I tried the following program unit in Microsoft Visual c++ 6.0 and the program caused unexpected behavior, #include <stdio.h> #include <string.h> int main() {
53
by: ¬a\\/b | last post by:
strlen is wrong because can not report if there is some error e.g. char *a; and "a" point to an array of size=size_t max that has no 0 in it
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:
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
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...
0
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,...
0
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...
0
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,...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.