Hello!
I am fairly new to C, and trying to learn to deal with malloc.
The objective for the code, is to allocate memory in order to store a string on the heap.
Compiler says "Warning: assignment makes integer from pointer without a cast"
"Warning: format '%s' expects type 'char *', but argument 2 has type 'int'"
"Warning: format '%s' expects type 'int', but argument 3 has type 'char *'"
All these 3 warning occurs 2 times each, of course.
I have read that the first warning is something you get if you forget to #include stdlib, which as you can see, I have not.
Seems to me I'm just being stupid, but I have been bangin my head on this one for a while now.
Using code::blocks IDE with GNU GCC.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void heapstrings(void)
{
char *p1 = malloc(sizeof(char[13]));
char *p2 = malloc(sizeof(char[13]));
*p1 = "Clydefrog";
*p2 = "Cartman";
printf("p1 is pointing on string %s at adress %d\n",*p1, p1);
printf("p2 is pointing on string %s at adress %d\n",*p2, p2);
}
int main()
{
heapstrings();
printf("Hello world!\n");
return 0;
}
Cheers