70,023
社区成员




#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LIM 81
char * mystrncpy(char * s1, char * s2, int n);
int main(void)
{
char s1[LIM];
char s2[LIM];
char * p;
int n;
printf("please input a string or q to quit:\n");
fgets(s2,LIM,stdin);
while(s2[0]!='q')
{
printf("please input the number of characters to copy:\n");
scanf("%d",&n);
getchar();
p=mystrncpy(s1,s2,n);
printf("the copy of s2 is:%s\n",*p);
printf("please input a string or q to quit:\n");
fgets(s2,LIM,stdin);
}
return 0;
}
char * mystrncpy(char * s1, char * s2, int n)
{
int i;
for(i=0;i<n&&(s2[i]!='\0');i++)
s1[i]=s2[i];
s1[i]='\0';
return s1;
}