Solved

question about '\0'

Posted on 2003-11-23
6
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

Independent Software Vendors: 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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

717 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