Home > Back-end >  An array of strings, please use the scanf writing prompt access conflict what reason be?
An array of strings, please use the scanf writing prompt access conflict what reason be?

Time:11-18

The code is as follows:
 
#include
Int main () {
Char STR [6].

Scanf_s (" % s ", STR);
Int CNT=0;
For (CNT=0; CNT & lt; 5; Cnt++) {
If (STR (CNT) & gt;='A' & amp; & STR (CNT) & lt;='B') {
STR (CNT) -='32';
}
Printf (" % s ", STR (CNT));
}

return 0;
}


Run to scanf_s that row times wrong is as follows:
 
0 x7ab1e63c (ucrtbased. DLL) (located in Project1. Exe) caused by abnormal: 0 xc0000005: when writing position 0 x00b00000 access conflict,


Which ensures that the input is 5 characters, such as: appLe,

CodePudding user response:

Scanf_s (" % 5 s ", STR, 6);
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l? View=MSVC - 160 & amp; ViewFallbackFrom=v - 2019

CodePudding user response:

reference 1/f, zhao teacher reply:
scanf_s (" % 5 s ", STR, 6);
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/scanf-s-scanf-s-l-wscanf-s-wscanf-s-l? View=MSVC - 160 & amp; ViewFallbackFrom=v - 2019

Thank you very much!

CodePudding user response:

reference
printf (" % s ", STR (CNT));
this output because of changed to:
 printf (" % c ", STR (CNT)); 

CodePudding user response:

 scanf_s (" % s ", STR, 6); 


Scanf_s and the difference between the scanf suggested that the building Lord search, then learn it
  • Related