Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 05-12-2008
cjohnman
I have a function that is changing the first letter in the month to lower case and I want to make a change that stops this from occuring. I believe I found a if statement that is making this change. My question is should I just make a change in the code below to say toupper where the first letter of each month is shown or find another solution because the first letter is already in upper case? If more info is needed from this small function I will glady post. Thanks.

[code]

123 if ((tolower(tmp_mon[0]) == 'j') &&
124 (tolower(tmp_mon[1]) == 'a') &&
125 (tolower(tmp_mon[2]) == 'n'))
126 ff_time.tm_mon = 0;
127 if ((tolower(tmp_mon[0]) == 'f') &&
128 (tolower(tmp_mon[1]) == 'e') &&
129 (tolower(tmp_mon[2]) == 'b'))
130 ff_time.tm_mon = 1;
131 if ((tolower(tmp_mon[0]) == 'm') &&
132 (tolower(tmp_mon[1]) == 'a') &&
133 (tolower(tmp_mon[2]) == 'r'))
134 ff_time.tm_mon = 2;
135 if ((tolower(tmp_mon[0]) == 'a') &&
136 (tolower(tmp_mon[1]) == 'p') &&
137 (tolower(tmp_mon[2]) == 'r'))
138 ff_time.tm_mon = 3;
139 if ((tolower(tmp_mon[0]) == 'm') &&
140 (tolower(tmp_mon[1]) == 'a') &&
141 (tolower(tmp_mon[2]) == 'y'))
142 ff_time.tm_mon = 4;
143 if ((tolower(tmp_mon[0]) == 'j') &&
144 (tolower(tmp_mon[1]) == 'u') &&
145 (tolower(tmp_mon[2]) == 'n'))
146 ff_time.tm_mon = 5;
147 if ((tolower(tmp_mon[0]) == 'j') &&
148 (tolower(tmp_mon[1]) == 'u') &&
149 (tolower(tmp_mon[2]) == 'l'))
150 ff_time.tm_mon = 6;
151 if ((tolower(tmp_mon[0]) == 'a') &&
152 (tolower(tmp_mon[1]) == 'u') &&
153 (tolower(tmp_mon[2]) == 'g'))
154 ff_time.tm_mon = 7;
155 if ((tolower(tmp_mon[0]) == 's') &&
156 (tolower(tmp_mon[1]) == 'e') &&
157 (tolower(tmp_mon[2]) == 'p'))
158 ff_time.tm_mon = 8;
159 if ((tolower(tmp_mon[0]) == 'o') &&
160 (tolower(tmp_mon[1]) == 'c') &&
161 (tolower(tmp_mon[2]) == 't'))
162 ff_time.tm_mon = 9;
163 if ((tolower(tmp_mon[0]) == 'n') &&
164 (tolower(tmp_mon[1]) == 'o') &&
165 (tolower(tmp_mon[2]) == 'v'))
166 ff_time.tm_mon = 10;
167 if ((tolower(tmp_mon[0]) == 'd') &&
168 (tolower(tmp_mon[1]) == 'e') &&
169 (tolower(tmp_mon[2]) == 'c'))
170 ff_time.tm_mon = 11;
• 05-12-2008
Dino
Just because a tolower() function is called on a character should not imply that the character is already in upper case.

The code you posted above simply turns a 3 character month into an index value of 0 to 11 (and is quite inefficient too)

Todd
• 05-12-2008
rdrast
In addition to Todd's comment above, that bunch of stuff there doesn't actually convert the case of anything. tolower() and toupper() only return the desired case, since there is no assignment back to the array, the original character remains unaffected.
• 05-12-2008
cjohnman
Ok so I need to find...
I will need to find what ff_time.tm_mon = 0,1,2.... means? I am thinking based on your replys I should find in a header file something stating if ff_time.tm_mon = 0
0 is somehow = jan

Is this where you guys would start searching?
• 05-12-2008
CodeGeek20
This looks to me like it's just checking to make sure the month designations are right and then assigning some value to them. I haven't been programming for long, so please tell me, are those ff_time and tm_mon things yours or preprogrammed system commands? Or is ff_time a struct, that's what the dot looks like. But if that's so, you're reassigning a new value to tm_mon in ff_time every time the month designators are right.

So, I guess my question is, what's going on here?

-CG20
• 05-12-2008
matsp
Quote:

Originally Posted by CodeGeek20
This looks to me like it's just checking to make sure the month designations are right and then assigning some value to them. I haven't been programming for long, so please tell me, are those ff_time and tm_mon things yours or preprogrammed system commands? Or is ff_time a struct, that's what the dot looks like. But if that's so, you're reassigning a new value to tm_mon in ff_time every time the month designators are right.

So, I guess my question is, what's going on here?

-CG20

Todd already explained that it assigns tm_mon with the value of month, starting with 0 for "jan".

the ff_time is a struct, probably the one described halfway down this page;
http://www.hmug.org/man/3/ctime.php

--
Mats
• 05-12-2008
cjohnman
ff_time is a struct:

[code]
77 struct tm ff_time;
78
79 int rt_stat,tmp_year;
80 char tmp_mon[4], tmp_date[13],tmp_time[9];
[\code]

And the purpose of this function is below:
15 * The ssw_igtoit (Ingres display time to integer time) procedure returns
16 * the long integer format time for the character display format
17 * DD-MMM-YYYY HH:MM:SS input time.

This function is being called from a 4GL file and changing my date from 12-May-2008 00:00:00 to 12-may-2008 00:00:00 and affecting other programs
• 05-12-2008
matsp
I personally would do something like this:
Code:

```int i; int found = 0; const char *month[] = { "jan", "feb", "mar" ...  }; for(i = 0; i < 3; i++)   tmp_mon[i] = tolower(tmp_mon); for(i = 0; i < 12; i++) {   if (strcmp(month[i], tmp_mon)== 0)   {       found = 1;       break;   } } if (found)   ff_time.tm_mon = i; else error("invalid month");  // You need to deal with this case somehow.```
This is probably marginally slower, but it's simpler to understand what it does.

--
Mats
• 05-12-2008
CodeGeek20
I guess this stuff is preprogammed then, forgive me, I haven't worked with calendar programs.

I would, however, write a function to go to the 0 element of tmp_mon, and set it to upper case. You will probably also have to write your own uppercase function if there's isn't a header for such things. I may be wrong, but from what I gather from the code, I think that may work.

If I can think of a function to do this I will post it. (And it might work ;))

-CG20
• 05-12-2008
CodeGeek20
Quote:

Originally Posted by matsp
Code:

`if (found)`

What's if(found) for? There's no conditional check.

-CG20
• 05-12-2008
matsp
Quote:

Originally Posted by CodeGeek20
What's if(found) for? There's no conditional check.

-CG20

?? It checks if found is true (which is "non-zero" in C). In this case, found is initialized to zero, and when we find a matching month-name, we set found = 1, and break the loop. So i will be the month number (starting from zero). If found is not true, the month name wasn't correct, so we need to deal with that in some way... [That probably shouldn't happen if the data is coming from a database, but...]

--
Mats
• 05-12-2008
cjohnman
This date is coming from a database
This date comes from a database column called entry_dt_tm and then the 4gl file trys to reset this date based on certain events. Thats where the problem lies because it just seems to call this function and then my date is out of proper case. I will look into this more and post back later. Thanks for all the help thus far...
• 05-12-2008
Dino
Carl, you could code up an UPDATE clause to fix all the dates. You'll need to use LIKE and substring, but it can be done.

Todd
• 05-12-2008
cjohnman
Was thinkin that
Todd thanks for your help. I was thinkin that would work but I have been told to find where the problem originates and correct it there. Are you thinking I should do an update in the 4GL file where my date is getting changed? I suppose I could try that. I just would like to find where it is altered and stop it there. Anyway I will look into your advice. You are usually rite. Thanks.
• 05-12-2008
Dino
There are two things to do.

1) Fix it at the source so it doesn't happen again.
2) Fix the data already in the database. This is what I was referring to.

Probably best to fix it at the source first, then fix the data in the database.

I'm not sure of the capabilities of your RDBMS, but perhaps you can define a Trigger to alter the incoming data (as it is INSERTED or LOADED) to be the proper format, thereby perhaps satisfying the requirement of "fixing it at the source"

Todd
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last