While programming an embedded system based on ATmega328p, I have encounter some char array problems in the C programming language.
I had a char array of exactly 8 chars ending with /0:
The solution code for me was:
- Mitko
char a[] = "///////0";It had trouble reading a[0] many times. For some still unknown reason, when I had:
char a[] = "10000000";it would corrupt some memory addresses close to the array and it never work as I wanted. The problem is not the '/0' at the end. '/0' it's NOT the null terminator (NUL character in ASCII). The null terminator is '\0'. I tried this with both, the C compiler in the Arduino's native IDE and the C compiler in the Atmel Studio 7 (with the Visual Micro installed) and it was the same exact thing. So, what's wrong? I still don't know, but I'm writing this blog post, because I fixed the problem by adding a random character in the front and in the back that would be never read by any actual code. Just for storing purposes. I can't reveal the whole code, but because of the trouble that I went through I don't recommend using char arrays now at all... :D
The solution code for me was:
char a[] = "/10000000/";
- Mitko