Questions tagged «strcpy»

10
为什么要使用strncpy而不是strcpy?
编辑:我已经为示例添加了源。 我遇到了这个例子: char source[MAX] = "123456789"; char source1[MAX] = "123456789"; char destination[MAX] = "abcdefg"; char destination1[MAX] = "abcdefg"; char *return_string; int index = 5; /* This is how strcpy works */ printf("destination is originally = '%s'\n", destination); return_string = strcpy(destination, source); printf("after strcpy, dest becomes '%s'\n\n", destination); /* This is …

9
strcpy与memcpy
memcpy()和之间有什么区别strcpy()?我试图在程序的帮助下找到它,但是两者都给出了相同的输出。 int main() { char s[5]={'s','a','\0','c','h'}; char p[5]; char t[5]; strcpy(p,s); memcpy(t,s,5); printf("sachin p is [%s], t is [%s]",p,t); return 0; } 输出量 sachin p is [sa], t is [sa]
81 c  memcpy  strcpy 

5
strcpy与strdup
我读到的strcpy是复制字符串,并strdup返回一个指向新字符串的指针以复制该字符串。 您能否解释一下您喜欢使用strcpy哪种情况以及您喜欢使用哪种情况strdup?
74 c  strcpy  strdup 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.