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


how to determine a number ending with 12

Posted on 2004-10-22
Medium Priority
Last Modified: 2010-04-01
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
Question by:justinY
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
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
LVL 12

Expert Comment

ID: 12382064
Hi justinY,


LVL 16

Expert Comment

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



Author Comment

ID: 12382097
Thanks, then how do I add one to the day ?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.

Author Comment

ID: 12382191
So, if I have

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

then I cannot use memcmp(), right ?
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)) {



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

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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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++.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question