i read the notes
it said character terminating null(\0) character
is it means if my statment is
scanf ("%s",$string);<---- here i input apple
printf ("%s",string);
then the output will become apple0 ?
i read the notes
it said character terminating null(\0) character
is it means if my statment is
scanf ("%s",$string);<---- here i input apple
printf ("%s",string);
then the output will become apple0 ?
scanf ("%s",$string);<---- here i input apple
printf ("%s",string);
Your scanf call is wrong, unless you're using it as pesudocode, just as an example. Anyway...
The 'NULL' terminator, '\0' is not displayed. It is simply used to tell the program when it's reached the end of the string. Think of it as punctuation at the end of a sentence. Punctuation signals you the reader, letting you know that the sentence has ended. You don't actually think of people saying the punctuation:
"Hello there period" "My name is Hot Stuff Eddie Gilbert period"
If you've ever seen reference to someone reading a telegram, they actually say the word "stop" whenever a sentence is ended. This is how telegrams denote the end of a sentence. This is similar to how the NULL works.
Quzah.
Hope is the first step on the road to disappointment.
When the books say strings in c/c++ are terminated by a null byte all that means is that there is some sort of sentinel value at the end of the string so that the compiler knows where the string will end. This sentinel value is a null byte.... '\0'
the \ means escape character
'\0' is normally 0 but then again it might not be so we always use the terminology '\0' to ensure that the correct representation of a null byte is placed after your string.
in memory your string will look like this....
'a' 'p' 'p' 'l' 'e' '\0'
but when its printed the null is not sent to the screen.So on the screen we get apple.
You need to sort out the syntax of your scanf() because there is no $ to identify strings in c/c++.
You also need to set aside some memory for your input. An array will be fine for this. for the string above you will need
char myarray[6]; // thats 5 for the chars and 1 for the null byte.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
oops... beaten to it!lol
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
thanks~Originally posted by Stoned_Coder
oops... beaten to it!lol
scanf is use & , not $
so,
scanf is use & , but not $, right??
scanf() takes pointers (i.e. addresses). & among other things is the address of operator so normally you would prefix your variable name with & to say you are passing the address of a variable. But an array name acts like a pointer to an array so there is no need to prefix an array name with &.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi