题解 | #截取字符串#
截取字符串
https://www.nowcoder.com/practice/a30bbc1a0aca4c27b86dd88868de4a4a
#include <stdio.h> #include <string.h> int main() { char a[1000]; int b; char data[1000] = { 0 }; scanf("%s",a); scanf("%d",&b); snprintf(data,b + 1,"%s", a); printf("%s\n",data); return 0; }
snprintf如果格式化后的字符串≥size,则赋值size -1个字符到data中