ZJGSU OJ 1997 子串複製(函式+字串+指標)[中]
阿新 • • 發佈:2020-12-11
技術標籤:c語言
非常簡單的一道題
題目描述
有一字串,包含n個字元。編寫一個函式,將此字串從第m個字元開始的全部字元複製成為另一個字串。要求在主函式中輸入字串及m值並輸出賦值結果。
輸入
輸入一個字串(可以包含空格的,且長度小於100),以及整數m。
輸出
輸出相應的子串。若m>n, 則輸出”Data error!”。
樣例輸入
Dennis Ritchie created the C programming.
7
樣例輸出
Ritchie created the C programming.
提示
#include<stdio.h> //1997
int main (){
char s[1000];
int m;
void pos(char *str,int m);
gets(s);
scanf("%d",&m);
pos(s,m);
return 0;
}
void pos(char *str,int m){
int i=0;
while(i<m && str[i]!='\0') i++;
if(i<m) printf("Data error!");
else printf("%s" ,str+i-1);
}