#define _CRT_SECURE_NO_WARNINGS 1
#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[])
{
? ? gets(s);
}
void strmcpy(char* t, int m, char* s)
{
? ? int k = 0;
? ? while (t[k])//計算位數(shù)
? ? {
? ? ? ? k++;
}
? ? for (int i = 0;i < m-1;i++)//在m-1位前變0
? ? {
? ? ? ? t[i] = 0;
? ? }
? ? for (int i = 0;i < MAXN;i++)//初始化S數(shù)組
? ? {
? ? ? ? s[i] = 0;
? ? }
? ? int n = 0;
? ? for (int i = 0;i < k;i++)
? ? {
? ? ? ? while (t[i])//遇到非0替換
? ? ? ? {
? ? ? ? ? ? s[n] = t[i];
? ? ? ? ? ? n++;
? ? ? ? ? ? break;
? ? ? ? }
? ? }
}
題目詳情 - 習(xí)題8-5 使用函數(shù)實現(xiàn)字符串部分復(fù)制 (pintia.cn)題目
因為沒有readstring函數(shù)在編譯器運(yùn)行不了往堡,所以加了readstring贬媒,如果要在pta上答題要把這個函數(shù)去掉。