题解 | #截取字符串#
截取字符串
http://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
#include<stdio.h>
#include<string.h>
int main()
{
char a[100]="\0";
char b[100]="\0";
int n;
while(scanf("%s",a)>0)//字符串不加&;>0对,!=0不对
{
scanf("%d",&n); //别忘了加&
}
strncpy(b, a,n);
printf("%s",b);
}
#include<string.h>
int main()
{
char a[100]="\0";
char b[100]="\0";
int n;
while(scanf("%s",a)>0)//字符串不加&;>0对,!=0不对
{
scanf("%d",&n); //别忘了加&
}
strncpy(b, a,n);
printf("%s",b);
}