Peter N Peter N - 1 year ago 193
C Question

'new' undeclared (first use in this function)

Why does this work in C++, but not in C? And what is the alternative for a C environment?

char *Buffer;
unsigned long Size;

Buffer = new char[Size]; // Throws an error in C, but not in C++

Answer Source

new and delete are not part of C. Please use malloc and free.

char *Buffer;
size_t Size = 100;
Buffer = malloc(Size);
if(Buffer == NULL) {
    puts("Bad allocation");
else {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download