reading a date with sscanf

后端 未结 1 443
闹比i
闹比i 2020-12-21 11:37

I\'ve got to read a date format (dd-mm-yyyy;) from a char* string using sscanf with this line of code:

sscanf(string, \"%[^-]-%[^-]-%[^;];\", day, month, yea         


        
相关标签:
1条回答
  • 2020-12-21 12:20

    You need to pass the address of the int variables:

    int day, month, year;
    sscanf(string, "%d-%d-%d;", &day, &month, &year);
    

    sscanf() returns the number of assignments made, recommend checking the return value before using day, month and year:

    if (3 == sscanf(string, "%d-%d-%d;", &day, &month, &year))
    {
    }
    
    0 讨论(0)
提交回复
热议问题