[英]copy one letter from a string into another
So I need to create a function that copies the characters from the even position of one string into a dynamically create new string and then return the new string.所以我需要创建一个函数,将字符从一个字符串的偶数位置复制到一个动态创建的新字符串中,然后返回新字符串。 If I send the function "ABCDEFG" it returns "ACEG".
如果我发送函数“ABCDEFG”,它返回“ACEG”。 How do you copy one character of a string into a new one in C?
如何将字符串的一个字符复制到 C 中的一个新字符中? I tried the strcpy function, but it just printed the whole string.
我尝试了 strcpy 函数,但它只是打印了整个字符串。
char * str(char *s1){
int i;
char *s2;
s2 = (char *)malloc(sizeof(char ));
for(i = 0; i < strlen(s1); i++){
if(i % 2 == 0){
///copy from s1 to s2
printf("s2: %s", s2);
}
}
return s2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.