With testing length of characters, I discovered very harm misunderstanding.
I usually wrote '\n' to mean 'NULL', but it's terribly wrong.
Here is my source code.
* Code *
#include <iostream>
#include <string.h>
#include <locale.h>
int main()
{
char* Str1 = "Count." ;
char* Str2 = "Count.\0" ;
char* Str3 = "Count.\n" ;
wchar_t* wStr1 = L"Count." ;
wchar_t* wStr2 = L"Count.\0" ;
wchar_t* wStr3 = L"Count.\n" ;
std::cout << "Length of " << Str1 << " =" << strlen(Str1) << std::endl ;
std::cout << "Length of " << Str2 << " =" << strlen(Str2) << std::endl ;
std::cout << "Length of " << Str3 << " =" << strlen(Str3) << std::endl ;
wprintf(L"Length of '%s' : %d\n", wStr1, wcslen(wStr1) );
wprintf(L"Length of '%s' : %d\n", wStr2, wcslen(wStr2) );
wprintf(L"Length of '%s' : %d\n", wStr3, wcslen(wStr3) );
// to stop to destroy
int i ;
std::cin >> i ;
return 0 ;
}
If you are a student who studies C++, let you guess the result.
Here is the result.
* Result
I have known '\n' means 'NULL', but it didn't.
'\n' means 'ENTER'.!!
'\0' means 'NULL'.
'old_Coding > C/C++' 카테고리의 다른 글
[C++] Function Pointer(2) (in class & with STL) (0) | 2009.12.27 |
---|---|
[C++] Function Pointer(1) (Global function & using array) (0) | 2009.12.27 |
[Scrap] length of characters (I/O Function) (*) (0) | 2009.12.25 |
[C++] Queue Linked List 작성 (0) | 2008.12.16 |
[C++] STACK Linked List 작성 (0) | 2008.12.16 |