用C自己写一个string copy函数 帮忙看看哪里写的不对
#include<iostream>using namespace std;
void stringcopy(char *p)
{
char *ps;
while(*p!='\0')
{
*ps=*p;
ps++;
p++;
}
cout<<ps<<endl;
}
void main()
{
char *p="abcdeffg";
stringcopy(p);
}
#include<iostream> #include<cstring> using namespace std; char* stringcopy(char*); int main() { char* pi="abcdefg"; char* ptr=stringcopy(pi); delete [] ptr; getchar(); return 0; } char* stringcopy(char* i) { char *pstr=new char[20],*head; cout<<i<<endl; head=pstr; while(*i!='\0') { *pstr++=*i++; } *pstr='\0'; return head; }