2020. 1. 30. 21:12ㆍ카테고리 없음
Scanf is a fairly kludgy tool. It expects the format to be exactly as you specified and if it isn't you get weird behaviour.You either need to enter the text exactly as specified (dd/mm/yy, not dd-mm-yy) or change how you go about things.Consider having scanf scan in a string that you then lex yourself to get the values you want - you can be much more tolerant of variances in the input that way, as well as be more proof against someone trying to break your program by deliberately giving it invalid input.
In this guide, we will show you how to print the date and time using the Linux command line in various formats.%c - locales date and time (full date and time)%C - short year (i.e 14, 15, 16). Date -d 'next Monday'. The n used in the printf statements is called an escape sequence. In this case it represents a newline character. After printing something to the screen you usually want to print something on the next line. If there is no n then a next printf command will print the string on the same line. Commonly used escape sequences are: n (newline) t (tab).
In your scanf, you have this format -%d/%d/%d but you are giving the input as, so you are doing wrong!Instead, you should give input as - and the%d/%d/%d part in scanf will ignore the / part from the input.I type in, but the result I get was 44-32766. Any idea guys?Yes, when you are giving as input, scanf assigning only 10 to date variable but no value to the other variables.
Since the other two variables month and year is uninitialized, you are getting garbage value (554502544 and 32766) when you print the value of variable month and year.One way to check this: Just initialize the variable and then take input. Int date = 0, month = 0, year = 0;scanf('%d/%d/%d', &date, &month, &year);Now, if you give as input, you will get 10-0-0 as output.
Print Next Date C Png
Hopefully you can understand what is actually happening!