Hello,
I am passing a char array. And clearing it and setting it with new data. However, in each case it only display the first 4 chars.
my output
main
load
fill
fill
I am tried using a combination of memmove and strncpy. But still couldn't get it to work. I thought it you pass it by reference you should be able to change the actual value. Which it does, but only the first 4 characters.
Many thanks for any advice
Code:
#include <string.h>
#include <stdio.h>
void load_buffer(char *buffer);
void fill_buffer(char *buffer);
int main()
{
char buffer[100];
strncpy(buffer, "main", strlen(buffer));
printf("%s\n", buffer);
load_buffer(buffer);
printf("%s\n", buffer);
getchar();
return 0;
}
void load_buffer(char *buffer)
{
memset(buffer, 0, sizeof(buffer));
strncpy(buffer, "Load_buffer", sizeof(buffer));
printf("sizeof buffer: %d %s\n", sizeof(buffer), buffer);
fill_buffer(buffer);
}
void fill_buffer(char *buffer)
{
memset(buffer, 0, sizeof(buffer));
memmove(buffer, "fill_buffer", sizeof(buffer));
printf("%s\n", buffer);
}