若m超過輸入字符串的長度,
#include <stdio.h>????? //超過字符串長度時則輸出空串,我的程序編寫哪里錯了
#define MAXN 20
void strmcpy( char *t, int m, char *s );
void ReadString( char s[] ); /* 由裁判實現,略去不表 */
int main()
{
??? char t[MAXN], s[MAXN];
??? int m;
??? scanf("%d\n", &m);
??? ReadString(t);
??? strmcpy( t, m, s );
??? printf("%s\n", s);
??? return 0;
}
void ReadString(char s[])
{
?? char s[MAXN];
gets(s);
}
void strmcpy( char *t, int m, char *s )
{
int i,j;
char tem;
for (i=m;i<MAXN;i++,j++)
{
tem=t[i];
s[i]=tem;
}
s[i]='\0';
}
2016-12-23
不懂你ReadString子函數要干嘛,不過子函數char s【MAXN】應該是不可以的,和char s【】重復定義了。改一下就好了。