Make buffer zero?
-
I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?
KIRAN PINJARLA
-
I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?
KIRAN PINJARLA
Use ZeroMemory(..) as ZeroMemory(buf, sizeof(buf));
Do your Duty and Don't expect the Result
-
I have char buf[10]; First i declared it as char buf[10] = {0}; In the middle of my code after using that buf, I again want to make buffer to zero. How to do that?
KIRAN PINJARLA
For platform independent code:
memset(buf, 0, 10);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
For platform independent code:
memset(buf, 0, 10);
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
better use sizeof(buf) instead of 10, it will save you some headache if someone changes the "char buf[10]" in future.
-
better use sizeof(buf) instead of 10, it will save you some headache if someone changes the "char buf[10]" in future.
I was using it to illustrate the call. sizeof will work on items declared on the stack, but not the heap. So, code like
char* pChar = new char[30]; cout << sizeof(pChar) << endl;
will output 4 instead of 30.If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac