C strcpy and strcat -
i have question strcpy , strcat.
in program i'm trying make need year born fiscal code. fiscal code given char serial port,
strcpy(temp, code[6]); strcat(temp, code[7]); yyyy = 1900 + (atoi(temp));
this came with: last 2 digits of year added 1900 (i know doesn't quite work people born in 2000). first digit copied full code temp variable using strcpy, add second digit use atoi , convert eveything integer; use strcat in way i've never seen before. doing right?
no need strcpy
/strcat
(and not appropriate in context anyway). no need temporary string either. can this:
yyyy = 1900 + (code[6] - '0') * 10 + (code[7] - '0');
this extracts 2 digit characters, converts each 1 integer in range 0..9, , calculates year these 2 values.
Comments
Post a Comment