单独的字符串和整数时sscanf_s访问冲突

时间:2016-10-12 20:51:42

标签: c++ scanf

    char a[200] = { 0 };

char tst[20] = "aaaa 123\n";
int i;
sscanf_s(tst, "%s %d",a, &i);
printf("reasult:%s %d", a,i);

无论我使用char tst[20] = "aaaa 123\n";还是char* tst = "aaaa 123\n";, 它始终显示访问冲突。 我需要从字符串中分隔一个字符串的整数。但为什么会这样呢?

1 个答案:

答案 0 :(得分:2)

sscanf_s期望 // default layout textPaint TextPaint defaultTextPaint = new TextPaint(textPaint); // spannable Spannable styledText = new SpannableString(mText); final BackgroundColorSpan backgroundColor = new BackgroundColorSpan(Color.YELLOW); final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.RED); final LeadingMarginSpan leadingMarginSpan = new LeadingMarginSpan.Standard(leading); final AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(leadSize); styledText.setSpan(foregroundColorSpan, highLightStart, highLightEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); styledText.setSpan(backgroundColor, highLightStart, highLightEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); styledText.setSpan(leadingMarginSpan, 0, mText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); styledText.setSpan(absoluteSizeSpan, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // add the line height check span if (android.os.Build.VERSION.SDK_INT == 23) { final vLineHeightCheckSpan checkHeightSpan = new vLineHeightCheckSpan(styledText, defaultTextPaint); styledText.setSpan(checkHeightSpan, 0, mText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } mLayout = new StaticLayout(styledText, defaultTextPaint, (int) initialRect.width(), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0, false); %c%s有两个参数,第二个参数是传递的缓冲区的大小。以下应该有效:

%[