Code 1
Code:
#include<stdio.h>
typedef struct
{
int n;
char *string;
}sct;
void fun(sct *);
int main(void)
{
sct one;
fun(&one);
printf("%s\n",one.string);
return 0;
}
void fun(sct *p)
{
char two[]="funny";
p->string=two;
printf("%s\n",p->string);
}
Output 1
Code 2
Code:
#include<stdio.h>
typedef struct
{
int n;
char *string;
}sct;
void fun(sct *);
int main(void)
{
sct one;
fun(&one);
printf("%s\n",one.string);
return 0;
}
void fun(sct *p)
{
//char two[]="funny";
p->string="funny";
printf("%s\n",p->string);
}
Output 2
So where my basics are wrong??
I need output 2 but it should in code 1's way.
What changes can i make in code 1?
thanks