how to determine a number ending with 12

Hi experts,

I have 2 columns as following:

char row_elem[50][50];

row_elem[6]                          row_elem[9]

17896412                              1/12/2004
18889712                              10/12/2004
19996512                              12/5/2004
98765409                              1/5/2004

I want to check row_elem[6], if ends with 12, then add 1 day in row_elem[9]. So the results should be

17896412                              1/13/2004
18889712                              10/13/2004
19996512                              12/6/2004
98765409                              1/5/2004

How can I do that ? Thanks
justinYAsked:
Who is Participating?
 
waysideConnect With a Mentor Commented:
If the strings vary in length you can do:

if (!memcmp("12", &row_elem[6][strlen(row_elem[6])-2], 2)) {

}

or

if (atoi(row_elem[6])%100 == 12) {
}

0
 
stefan73Commented:
Hi justinY,
if(!memcmp("12",&row_elem[6],2)){
    ...
}


Cheers!

Stefan
0
 
imladrisCommented:
You can check for a number ending in 12 by dividing by 100 and taking the remainder:

if(row_elem[6]%100==12)

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
justinYAuthor Commented:
Thanks, then how do I add one to the day ?
0
 
imladrisCommented:
Sorry, your row_elem are character; I missed that. A comparison would be better in that case.

The memcmp that Stefan relevantly proposes is a good test. It requires that the numbers all be the same length.
0
 
justinYAuthor Commented:
So, if I have

17896412                          1/13/2004
78912                               2/13/2004

then I cannot use memcmp(), right ?
0
 
stefan73Commented:
> how do I add one to the day ?

Use a time_t variable (which is the number of seconds since 01/01/1970), and add 60*60*24 = 86400. You can then convert it back to a struct tm* by localtime().

That eliminates lengthy calendar operations, like checking for end-of-month, leap years and such.
0
All Courses

From novice to tech pro — start learning today.