允许用标准库吗,可以的话就很简单啊,用strlen #include<stdio.h> char *substrcpy(char *str, int m) { if (m > strlen(str)) return NULL; else return str + m; }
第3个回答 2019-12-18
#include<stdio.h> char *substrcpy(char *str,int m) { int n; n=0; while ( str[n] ) n++; if ( n>m ) return str+m; else return NULL; } void main() { char s[256],*p; int m; scanf("%s%d",s,&m); p=substrcpy(s,m); if ( p ) printf("%s\n",p); }