i am trying to implement C style strings in C++ (from chapter 4 "C++
Primer 4/e"):
// reading from std::cin for a c-string
// (a null terminated character array)
#include <iostream>
#include <string>
int main() {
// reading c style character array from std::cin
const int arr_sz = 7;
char c;
int i = 0;
char ca[arr_sz];
for(char *pbegin = ca, *pend = ca + arr_sz;
pbegin != pend; ++pbegin)
{
if(i == 6)
*pbegin = '\0';
else
{
std::cout << "Enter a character: ";
std::cin >c;
*pbegin = c;
++i;
}
}
std::cout << "wrote the array, here is the output:\t";
// printing out array
for(char *pbegin = ca, *pend = ca + arr_sz;
pbegin != pend;
++pbegin)
{
std::cout << *pbegin;
}
std::cout << std::endl;
}
/* OUTPUT
unix@debian:~/programming$ ./a.out
Enter a character: A
Enter a character: R
Enter a character: N
Enter a character: U
Enter a character: L
Enter a character: D
wrote the array, here is the output: ARNULD^@
unix@debian:~/programming$
*/
i want to know what does the character "^@" represent, is this null
character, '\0', that i put in the code or something else. also this
is the output from "Emacs shell", BASH does not print this character.
Why?
thanks
-- "arnuld"
http://arnuld.blogspot.com