I am using the following code to copy the string contents to another string. Two logics are used ,One with while loop(commented) is working and the other is not (as=at).
Please help me to identify the flaw in this code.
Thanks in advance
#include<stdio.h>
#include<conio.h>
main()
{
char *s="SourceString";
char *t="TargetString";
void print(char *s);
void strcopy(char *s,const char *t);
print(s);
strcopy(s,t);
print(s);
getch();
}
void strcopy(char *as,const char *at)
{
/*while((*as=*at)!='\0') // working
{
as++;
at++;
} */
as=at; //not working
}
void print(char *s)
{
printf("\n Printing the Contents:");
for(;*s!='\0';s++)
printf("%c",*s);
printf("\n END");
}
All are saying that the strings are passed by Value and not by address. But I am passng the address of the strings in calling functiona nd in called function am using pointers. Please clarify I am new to pointers