whitespace in the format string (scanf)

前端 未结 4 1960
日久生厌
日久生厌 2020-12-05 12:23

Consider the following code:

#include
int main() {
    int i=3, j=4;
    scanf(\"%d c %d\",&i,&j);
    printf(\"%d %d\",i,j);
    retu         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 12:43

    Force a string parsing first :

    char a[100], b[100];
    scanf("%99s c %99s", a, b);
    

    Then use sscanf() to convert the strings to int.

提交回复
热议问题