Solved

question about '\0'

Posted on 2003-11-23
6
325 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Details to do the search 56 144
Way to improve it 16 59
C dll call freezes 5 88
How to create frequencies of a variable from SAS dataset? 10 116
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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now