char NumberType[] = "POSITIVE";
...
if (Number <0)
{
NumberType[10] = "NEGATIVE";
}
In C, the proper way to write a string into a destination char[] buffer is to use a function like strcpy
. For example:
// Instead of NumberType[10] = "NEGATIVE" use:
strcpy(NumberType, "NEGATIVE");
Even better, Microsoft implemented a series of safer functions to operate with strings in C, for example, the "safer" equivalent of strcpy is strcpy_s. Basically, when you use these safer functions, you pass an additional parameter that specifies the size of the destination buffer. In this way, the strcpy_s function is able to prevent buffer overflows (i.e. writing data outside proper buffer boundaries), which are a source of dire bugs and security problems.
The above code can be rewritten using the safer strcpy_s like this:
// A safer version of the previous strcpy call.
// Note the additional _countof(NumberType)
// to specify the size of the destination buffer.
strcpy_s(NumberType, _countof(NumberType), "NEGATIVE");
If you can use C++ instead of pure C, you can enjoy writing even safer and simpler code, for example using the std::string class, and its overloaded operator= for copying strings. For example:
#include <string> // for std::string
...
std::string numberType = "POSITIVE";
...
if (...) {
numberType = "NEGATIVE";
}