M
Martin Andert
Why ist the following code not working?
I want to initialize a string in function, but I am
getting those STATUS_ACCESS_VIOLATION exceptions.
#include <stdio.h>
#include <stdlib.h>
void init(char* buffer)
{
buffer = (char*) malloc(6 * sizeof(char));
buffer[0] = 'H';
buffer[1] = 'e';
buffer[2] = 'l';
buffer[3] = 'l';
buffer[4] = 'o';
buffer[5] = '\0';
}
int main()
{
char* buffer;
init(buffer);
printf("%s", buffer);
}
Any workaround or how to for this?
TIA,
Martin
I want to initialize a string in function, but I am
getting those STATUS_ACCESS_VIOLATION exceptions.
#include <stdio.h>
#include <stdlib.h>
void init(char* buffer)
{
buffer = (char*) malloc(6 * sizeof(char));
buffer[0] = 'H';
buffer[1] = 'e';
buffer[2] = 'l';
buffer[3] = 'l';
buffer[4] = 'o';
buffer[5] = '\0';
}
int main()
{
char* buffer;
init(buffer);
printf("%s", buffer);
}
Any workaround or how to for this?
TIA,
Martin