calculate the days between two dates

前端 未结 2 1008
傲寒
傲寒 2021-01-29 13:18

I did a program that calculates the days different, between two dates, but I am not sure how can I add a statement that makes sure the program wont include the end date.

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 13:43

    You can check if argv[7] is "include" using strcmp from , and set a variable to ignore the end date if it's not

        /* Rest of the code above */
    
        if (mm2= 8)
        {
            if (strcmp("include", argv[7]) == 0)
            {   
                include = 1;
            }
        }
    
        day_diff = dd2 - dd1;
        if (include == 0)
        {
            day_diff--;
        }
        printf("%d", day_diff);
    
        return 0;
    

    But i recommend you search about getopts, a flag seems more user friendly
    ./daysCalculatorA -i 19 2 2019 22 4 2019

提交回复
热议问题