Solved

question about '\0'

Posted on 2003-11-23
6
334 Views
Last Modified: 2010-05-18
When I enter a char array of numbers will I need to add the \0 char as you do with words?
0
Comment
Question by:buckeyes33
  • 4
6 Comments
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9806670
The \0 character only specifies the logical end of a, let's use your term, "word." We can have a character array that is 80 characters in length but the "word" would occupy up to just before this \0 character.
So char arr[80] = "Hello"; would make this happen:
arr [0][1][2][3][4][5][6][7][8]...
      'H' 'e' 'l'  'l'  'o''\0' *  *  * ...
(all *'s stand for garbage data).
If using this argument to answer the question above, then, no you don't have to include the '\0' character because it does not necessarily clarify anything.
0
 
LVL 4

Accepted Solution

by:
n_fortynine earned 125 total points
ID: 9806760
Well, unless you want to manipulate the entire array as a number itself using some string-related methods. In that case, you should. :)
0
 
LVL 9

Author Comment

by:buckeyes33
ID: 9806779
Yes i am using it as a string.  So I will want to use it.  I thought so but I was not completly sure.  Thanks.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:harishg2
ID: 9816526
no need of it because string itself means that array of characters with a NULL '\o'  at the end of it .
 thank u very much
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9818446
>>no need of it because string itself means that array of characters with a NULL '\o'  at the end of it .
that is, IF some other process did it FOR you, i.e. if you use some streams to put data in there then yes, you do not have to manually set the null character. BUT, if I want to use an array of numbers as a whole number itself I DO want to do that. An array of characters which are numbers are not necessarily a string UNTIL you make it so (or have somebody done it for you making you think it's done under every circumstances).

FYI, it's '\0' (zero) not '\o'
0
 
LVL 4

Expert Comment

by:n_fortynine
ID: 9818454
>>are not necessarily
should read : is not necessarily
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

733 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