C++ 给定字符串,然后给出开始要取的位置,返回取到的信息
3
happy new year
7
year
1
new
4
new year
year
error input
#include <stdio.h> #include <string.h> void strmcpy(char* s, char* t, int m); int main() {int repeat, m;char t[1000], s[1000];scanf("%d", &repeat);getchar(); //吸收换行符int i;for (i = 0; i < repeat; i++) {scanf("%[^\n]", t);scanf("%d", &m);getchar();strmcpy(s, t, m);if (strlen(s) != 0)printf("%s\n", s);elseprintf("error input\n");}return 0; } void strmcpy(char* s, char* t, int m) {t = t + m - 1;while (1) {*s = *t;if (*s == '\0')break;t++;s++;} }