The reproduceable error code is:
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//#include <cstring>
//functions
#define true 1
#define false 0
#ifdef _MSC_VER
// define POSIX function strndup if not available
char* strndup(const char* s, size_t n) {
size_t len;
for (len = 0; len < n && s[len]; len++)
continue;
char* ptr = malloc(len + 1);
if (ptr) {
memcpy(ptr, s, len);
ptr[len] = '\0';
}
return ptr;
}
#endif
char** split(const char* str, const char* delimiters, int** a, int* size_of_a) {
int i, count, len;
char** final_result;
const char* p;
// phase 1: count the number of tokens
p = str + strspn(str, delimiters);
for (count = 0; *p; count++) {
p += strcspn(p, delimiters);
p += strspn(p, delimiters);
}
// phase 2: allocate the arrays
final_result = calloc(sizeof(*final_result), count + 1);
if (a) {
*a = calloc(sizeof(**a), count);
}
if (size_of_a) {
*size_of_a = count;
}
// phase 3: copy the tokens
p = str;
for (i = 0; i < count; i++) {
p += strspn(p, delimiters); // skip the delimiters
len = strcspn(p, delimiters); // count the token length
if (a) {
(*a)[i] = len;
}
final_result[i] = strndup(p, len); // duplicate the token
p += len;
}
final_result[count] = 0;
return final_result;
}
#ifdef __cplusplus
}
#endif
It started to give error:
Severity Code Description Project File Line Suppression State
Error C2440 'initializing': cannot convert from 'void *' to 'char *' example_win32_directx9 C:\Libraries\ImGui\imgui\examples\example_win32_directx9\Equation_simplifier.c 77
How can this be fixed? I have set my compiler to C++14 and I am using visual studio 2019. I am using this in a non-main cpp file which is called in main cpp file. The main error I am getting from is malloc and calloc from what I have noticed. I am also getting error for getch().