manichandra
Technical User
what is wrong with this code? its not working . can anybody explain in detail please ???
____________________________
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void newStrCpy(char* q, char* p);
int main (void)
{
char *q = "MANICHANDRA";
char *p ;
newStrCpy(q,p);
//printf("%d",(int)p);
printf("%s\n",p);
return 0;
}
void newStrCpy(char* q, char* p)
{
//printf("%d",(int)p);
char *temp =(char*) malloc(sizeof(*q));
int i=0;
do{
*(temp+i) = *(q+i);
i++;
}
while(*(q+i)!='\0');
//printf("%s",temp);
p = temp;
}
____________________________
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void newStrCpy(char* q, char* p);
int main (void)
{
char *q = "MANICHANDRA";
char *p ;
newStrCpy(q,p);
//printf("%d",(int)p);
printf("%s\n",p);
return 0;
}
void newStrCpy(char* q, char* p)
{
//printf("%d",(int)p);
char *temp =(char*) malloc(sizeof(*q));
int i=0;
do{
*(temp+i) = *(q+i);
i++;
}
while(*(q+i)!='\0');
//printf("%s",temp);
p = temp;
}