Is that the exact code?
- Two semicolons after malloc
- Only allocate 5 bytes for a 7 byte string (6 + '\0')
- Worse, strcpy will gladly do it for you, so you're EXACT string will be 'rajes' with no null-terminator.
And please use [ code ] [ /code ] blocks, without the spaces in them. If people are going to read your code the least you could do is make it readable for them.
Code:
#include<stdio.h>
#include<pthread.h>
void *thrdfun(void *arg)
{
printf("hi world..\n");
return NULL;
}
int main()
{
pthread_t thread;
char *ptr = malloc(7);
strcpy(ptr,"rajesh");
printf("%s\n",ptr);
printf("Hi...\n");
pthread_create(&thread,NULL,thrdfun,NULL);
return 0;
}
And really, why do you have that strcpy stuff in there? I'd remove the printf(...)'s, the char *ptr and strcpy and start from the beginning.
Code:
#include <stdio.h>
#include <pthread.h>
void *thrdfun(void *arg)
{
printf("hi world..\n");
return NULL;
}
int main()
{
pthread_t thread;
/* pthread_create returns 0 on success */
if(pthread_create(&thread,NULL,thrdfun,NULL) != 0) {
printf("simple.c: error creating pthread, exiting\n");
return -1;
}
return 0;
}
I'd try that and see what happens, post errors after running it.