• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

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
0
justinY
Asked:
justinY
  • 2
  • 2
  • 2
  • +1
1 Solution
 
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
 
justinYAuthor Commented:
Thanks, then how do I add one to the day ?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
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
 
waysideCommented:
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:
> 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now