G
Gary
I'm confused about the two ways of string copy below. The first one
(two functions) works; the second doesn't. Can anybody explain the
reason to me? Thanks a lot.
#include <stdio.h>
/*this one works well
void copy (char *s, char *t)
{
int i = 0;
while ((*t++ = *s++) != '\0')
;
}
main ()
{
char *s = "abcde";
char *t;
copy (s, t);
printf ("%s\n", t);
}
*/
//put all of them together in main, why "Segmentation fault"?
main ()
{
char *s = "abcde";
char *t;
int i = 0;
while ((*t++ = *s++) != '\0')
;
printf ("%s\n", t);
}
(two functions) works; the second doesn't. Can anybody explain the
reason to me? Thanks a lot.
#include <stdio.h>
/*this one works well
void copy (char *s, char *t)
{
int i = 0;
while ((*t++ = *s++) != '\0')
;
}
main ()
{
char *s = "abcde";
char *t;
copy (s, t);
printf ("%s\n", t);
}
*/
//put all of them together in main, why "Segmentation fault"?
main ()
{
char *s = "abcde";
char *t;
int i = 0;
while ((*t++ = *s++) != '\0')
;
printf ("%s\n", t);
}