[Info-vax] Significance of 2020 / 2021 date

Chris xxx.syseng.yyy at gfsys.co.uk
Sat Jan 9 07:50:11 EST 2021


On 01/09/21 12:35, Andy Burns wrote:
> Chris wrote:
>
>> issinoho wrote:
>>
>>> if (atoi (date_string + 5)>  2020)
>>
>> That code is type unsafe for starters. atoi() requires an ascii string,
>> but you are trying to add 5 decimal to an ascii string ?.
>
> atoi requires a *pointer* to an asciiz string, presumably in this case
> the format is something like DDMMMYYYY, so that the +5 starts the
> decimal conversion from the address of the first Y.
>

Ok, but I would not be doing pointer arithmetic inside an ancient
library function such as atoi(). Expecting the compiler to a be a
mindreader etc.

Ideally, you get the user input, parse it to verify correct format and
only then, pass the year field to the conversion routine. Only a few
lines of added code needed to do it right.

Chris



More information about the Info-vax mailing list