蛮简单的,直接上代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#define MAXN 20
void strmcpy(char* t, int m, char* s);
int main(){
char t[MAXN], s[MAXN];
int m;
scanf("%d\n", &m);
gets(t);
strmcpy(t, m, s);
printf("%s\n", s);
return 0;
}
void strmcpy(char* t, int m, char* s) {
int a = 0, i = 0, b = 0, j = 0;
for (i = 0; t[i] != '\0';i++) {
if (i == m - 1) {//因为i从0开始,所以m-1
a = i;//找到等于m的数
}
}
b = i;//这里的i经过了上面的循环,现在的i的值就是数组的长度。
if (m > b) {//判断是否越界
s[j] = NULL;
}
else {
for (i = a; t[i] != '\0'; i++) {//从第m(a)个值开始,往数组s中输入
s[j] = t[i];
s++;
}
s[j] = '\0';
}
}