Lesson 25: C Programming - sscanf - how to parse a date string and store into individual variables.

preview_player
Показать описание
This program uses the C standard library function sscanf() to parse a date string in the format of "YYYY/MM/DD" and assign the corresponding year, month, and day values to the variables year, month, and day respectively.

The program starts by including the header file stdio.h which contains declarations for input/output functions like printf() and sscanf(). Then it declares three variables of type int to store the year, month, and day values.

Next, it declares a char pointer str and assigns it a string literal "2023/03/28" that represents a date in the desired format.

The sscanf() function is then called with the str string as the input parameter, along with a format string "%d/%d/%d" that specifies the expected format of the input string. The function scans the input string and extracts the integer values for year, month, and day using the format specifier %d and stores them in the corresponding variables year, month, and day using the & operator to pass their addresses.

Finally, the printf() function is used to output the date in the format of "MM/DD/YYYY" using the format string.

@SoftwareNuggets #softwarenuggets #softwareNuggetsShorts #cprogrammingshorts #Shorts
Рекомендации по теме
welcome to shbcf.ru