c语言:编写函数mstrcpy(char *t,char *s,int m)字符串,我好像错了好多
答案:1 悬赏:50
解决时间 2021-01-19 00:38
- 提问者网友:回忆在搜索
- 2021-01-18 19:47
c语言:编写函数mstrcpy(char *t,char *s,int m)字符串,我好像错了好多
最佳答案
- 二级知识专家网友:污到你湿
- 2021-01-18 19:55
第:些复杂(写)
#include
#include
void strmcpy(char *s, char *t, int m);
int main(void)
{
char s[80], t[80];
int m;
printf("Input a string: ");
gets(t);
printf("Input an integer: ");
scanf("%d", &m);
strmcpy(s, t, m);
printf("Output is: %s", s);
return 0;
}
void strmcpy(char *s, char *t, int m)
{
int i;
for (i = 0; t[m] != '\0'; i++)
{
*(s + i) = *(t + m);
m++;
}
*(s + i) = '\0';
}
第二种:
#include
#include
void strmcpy(char *s, char *t, int m);
int main(void)
{
char s[80], t[80];
int m;
printf("Input a string: ");
gets(t);
printf("Input an integer: ");
scanf("%d", &m);
strmcpy(s, t, m);
printf("Output is: %s", s);
return 0;
}
void strmcpy(char *s, char *t, int m)
{
strcpy(s, t + m);
}
#include
#include
void strmcpy(char *s, char *t, int m);
int main(void)
{
char s[80], t[80];
int m;
printf("Input a string: ");
gets(t);
printf("Input an integer: ");
scanf("%d", &m);
strmcpy(s, t, m);
printf("Output is: %s", s);
return 0;
}
void strmcpy(char *s, char *t, int m)
{
int i;
for (i = 0; t[m] != '\0'; i++)
{
*(s + i) = *(t + m);
m++;
}
*(s + i) = '\0';
}
第二种:
#include
#include
void strmcpy(char *s, char *t, int m);
int main(void)
{
char s[80], t[80];
int m;
printf("Input a string: ");
gets(t);
printf("Input an integer: ");
scanf("%d", &m);
strmcpy(s, t, m);
printf("Output is: %s", s);
return 0;
}
void strmcpy(char *s, char *t, int m)
{
strcpy(s, t + m);
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯