This is my code.
#include <stdio.h> void abc(char *text); int main(void) { char text[20]; abc(text); printf("text in main : %s\n",text); return 0; } void abc(char *text) { text = "abc"; printf("text in abc function : %s\n",text); }
And it is deduced.
text in abc function : abc text in main : ฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬฬ๑ป ๚
My questions:
abc
scanf
When you call the function:
abc(text);
a copy of the pointer is created text, and this pointer is used in the function abc(). So when you say:
text
abc()
text = "abc";
you change the copy, not back to main.
main
, C - , strcpy(). , :
strcpy()
strcpy( text, "abc" );
printf("text in main : %s\n",text); C, strcpy(), char ! , .
printf("text in main : %s\n",text);
int i; for (i=0 ; i<strlength(text);i++) { printf ("%d",text[i]); }