关于scanf格式控制字符串之间加入,的问题,请指教

[复制链接]
查看11 | 回复6 | 2021-1-27 06:45:35 | 显示全部楼层 |阅读模式
inta,b;
scanf("%d,%d",&a,&b);
printf("%d\n%d\n",a,b);
输入4345
我知道应该输入43,45
但为什么b显示37而不是别的数?
如果把逗号改为别的字符,b也是37
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
我知道了,b的初始化值即为37
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
不会这样啊~
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
那为什么数据没有存入b中呢
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
随机的


回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
不会这样,注意输入的是逗号是英语下还是中文下的
回复

使用道具 举报

千问 | 2021-1-27 06:45:35 | 显示全部楼层
FormatSpecificationFields:scanfandwscanfFunctions
Aformatspecificationhasthefollowingform:
%
  • [width][{h|l|I64|L}]type
    Theformatargumentspecifiestheinterpretationoftheinputandcancontainoneormoreofthefollowing:
    White-spacecharacters:blank('');tab('\t');ornewline('\n').Awhite-spacecharactercausesscanftoread,butnotstore,allconsecutivewhite-spacecharactersintheinputuptothenextnon–white-spacecharacter.Onewhite-spacecharacterintheformatmatchesanynumber(including0)andcombinationofwhite-spacecharactersintheinput.

    Non–white-spacecharacters,exceptforthepercentsign(%).Anon–white-spacecharactercausesscanftoread,butnotstore,amatchingnon–white-spacecharacter.Ifthenextcharacterinstdindoesnotmatch,scanfterminates.

    Formatspecifications,introducedbythepercentsign(%).Aformatspecificationcausesscanftoreadandconvertcharactersintheinputintovaluesofaspecifiedtype.Thevalueisassignedtoanargumentintheargumentlist.
    Theformatisreadfromlefttoright.Charactersoutsideformatspecificationsareexpectedtomatchthesequenceofcharactersinstdin;thematchingcharactersinstdinarescannedbutnotstored.Ifacharacterinstdinconflictswiththeformatspecification,scanfterminates,andthecharacterisleftinstdinasifithadnotbeenread.
    Whenthefirstformatspecificationisencountered,thevalueofthefirstinputfieldisconvertedaccordingtothisspecificationandstoredinthelocationthatisspecifiedbythefirstargument.Thesecondformatspecificationcausesthesecondinputfieldtobeconvertedandstoredinthesecondargument,andsoonthroughtheendoftheformatstring.
    Aninputfieldisdefinedasallcharactersuptothefirstwhite-spacecharacter(space,tab,ornewline),oruptothefirstcharacterthatcannotbeconvertedaccordingtotheformatspecification,oruntilthefieldwidth(ifspecified)isreached.Iftherearetoomanyargumentsforthegivenspecifications,theextraargumentsareevaluatedbutignored.Theresultsareunpredictableiftherearenotenoughargumentsfortheformatspecification.
    Eachfieldoftheformatspecificationisasinglecharacteroranumbersignifyingaparticularformatoption.Thetypecharacter,whichappearsafterthelastoptionalformatfield,determineswhethertheinputfieldisinterpretedasacharacter,astring,oranumber.
    Thesimplestformatspecificationcontainsonlythepercentsignandatypecharacter(forexample,%s).Ifapercentsign(%)isfollowedbyacharacterthathasnomeaningasaformat-controlcharacter,thatcharacterandthefollowingcharacters(uptothenextpercentsign)aretreatedasanordinarysequenceofcharacters,thatis,asequenceofcharactersthatmustmatchtheinput.Forexample,tospecifythatapercent-signcharacteristobeinput,use%%.
    Anasterisk(*)followingthepercentsignsuppressesassignmentofthenextinputfield,whichisinterpretedasafieldofthespecifiedtype.Thefieldisscannedbutnotstored.
  • 回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    主题

    0

    回帖

    4882万

    积分

    论坛元老

    Rank: 8Rank: 8

    积分
    48824836
    热门排行