A
Abhayks
Hi,
I am retuning to "C" after a long time and my basics are shatterred.
Not sure where I am making the mistake.
Please help.
#include<stdio.h>
#include<stdlib.h>
void foo( char ** ptr)
{
int i;
*ptr = malloc(255); // allocate some memory
// strcpy( *ptr, "Hello World");
for( i=0; i<5; i++)
{
*ptr='a';
}
}
int main()
{
char *ptr = 0;
// call function with a pointer to pointer
foo(&ptr );
printf("%s\n", ptr);
// free up the memory
free(ptr);
return 0;
}
Please advise why this is not working?
I am retuning to "C" after a long time and my basics are shatterred.
Not sure where I am making the mistake.
Please help.
#include<stdio.h>
#include<stdlib.h>
void foo( char ** ptr)
{
int i;
*ptr = malloc(255); // allocate some memory
// strcpy( *ptr, "Hello World");
for( i=0; i<5; i++)
{
*ptr='a';
}
}
int main()
{
char *ptr = 0;
// call function with a pointer to pointer
foo(&ptr );
printf("%s\n", ptr);
// free up the memory
free(ptr);
return 0;
}
Please advise why this is not working?