[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# how to determine a number ending with 12

Posted on 2004-10-22
Medium Priority
237 Views
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
Question by:justinY
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2
• 2
• +1

LVL 12

Expert Comment

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

Cheers!

Stefan
0

LVL 16

Expert Comment

ID: 12382077
You can check for a number ending in 12 by dividing by 100 and taking the remainder:

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

0

Author Comment

ID: 12382097
Thanks, then how do I add one to the day ?
0

LVL 16

Expert Comment

ID: 12382103
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

Author Comment

ID: 12382191
So, if I have

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

then I cannot use memcmp(), right ?
0

LVL 14

Accepted Solution

wayside earned 500 total points
ID: 12384837
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

LVL 12

Expert Comment

ID: 12398224
> 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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generatâ€¦
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticallâ€¦
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Botâ€¦
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
###### Suggested Courses
Course of the Month12 days, 15 hours left to enroll