subith86 17 Junior Poster

Common mistake that everybody makes. :)
Line 21 : use "&" in scanf

Ancient Dragon commented: Good observation -- I missed that :) +17
subith86 17 Junior Poster

oh come on!!!
I should not have spoon fed :(

1. There is no harm in using int variables. change unsigned to int.
2. += can be replaced with ordinal_day = ordinal_day + month;
3. Last but not least, you must have a bool function for leap year check. I didn't take the pain in writing one for you. So I put a comment inside if-condition. You have to call a bool function, inside the if-condition. The argument to that function should be the year and it returns true or false.

subith86 17 Junior Poster

The program can be greatly simplified

But the reason why he did this way is to output the count down. In fact, count up. Starts from 0:00 to 1:30

subith86 17 Junior Poster

Yes it is, but not the way I want.
The output is different

It's pretty simple. You are not looping fully while printing. Make this change in line 40 - 43 (extra line added) and it will work.

for( i=0; i<c ; i++) {
    printf("%c", line[i]);
}
printf("%c", line[i]);
subith86 17 Junior Poster

Oh, no!!!
No while loop to check for validity. But since you are a beginner, I understand you'll take some time to get a hang of things.

Validations are like checking whether a condition is met or not. And for a condition, the right candidate is if(condition).

Something like this

if((mm > 0) && (mm <= 12) && (dd > 0) && (dd <= 31) && (yyyy >= 0))
{
    //valid
}
else
{
    //invalid
}

But there is a problem here. If a user enter Feb-31, it gets validated. So the validation thing is a bit complex for a 2-week guy. You have to use a very complicated if-condition to achieve the purpose. Or, I would go with arrays. Storing the number of days in each month in an array and validating it. But I don't think so that you are taught arrays by this time. So, leave the validation part as of now.

Now coming to your existing code, i feel the else part is not needed. The three possibilities between two integers are '<', '>' and '==' all of which are handled in separate blocks. Whatever combination of integers you give, it will never reach the "else" part.

And glad to see that you are using int main(void) as the prototype of your main function, unlike other beginners (including me, when I was a beginner) who use void main() :) Also mark the thread as solved, when done :)

subith86 17 Junior Poster

I don't see any validity checks done for your dates. He can enter invalid dates like 33/33/2012.
Once the dates are validated, the job is easy.

day1 = yyyy1 * 10000 + mm1 * 100 + dd1
day2 = yyyy2 * 10000 + mm2 * 100 + dd2

Check which is greater out of day1 and day2. So simple, isn't it :P

But there is another potential error in your program. Your variables mm1, dd1 are declared as integers and in your console out put you ask the user to enter in mm/dd/yyyy format. So for September, the user will enter "09". But since mm1 is declared as int, "09" will be treated as octet number and you'll get run time errors, since 8 & 9 are not allowed in octet system. So better use strings.

subith86 17 Junior Poster

check this link, this should help you
http://linux.die.net/man/3/strtol

For C++ programmers, there is another solution
http://www.cplusplus.com/articles/numb_to_text/

subith86 17 Junior Poster

once it gets back to process_and_display_information, the data is gone.

Yes, it will be gone, because the scope of myStrings is only within tokenize_urls(). myStrings is created in the stack and once the control goes out of tokenize_urls(), the memory will be freed. That is why you lose your data at process_and_display_information().

To solve this, you have to allocate memory for myStrings using new. By this way, the data of myStrings will be stored in heap. Even if tokenize_urls() finishes it's job, myStrings will still be there in heap and can be accessed by process_and_display_information(). Remember to delete the memory in process_and_display_information() once you are done using myStrings.

Another way to solve this is to declare myStrings in process_and_display_information() and pass it by reference to tokenize_urls(). Let tokenize_urls() be a void function and let it modify myStrings. So when you get back to process_and_display_information() you will have the modified myStrings with you.

I prefer the second method because it doesn't involve any memory allocation and delallocation to be taken care by the programmer.

freedomflyer commented: Very, very clear and well thought out explanation. Even bolded terms and such to make it more clear. +0
subith86 17 Junior Poster

you are using getch(), clrscr() all of which are part of <conio.h> which you haven't included. It is also suggested not to use <conio.h> as it is not standard and not supported in many compilers.

You are returning 0 in line 272, but your main function's return type is void. Avoid it.

As said in the previous post, avoid using goto statements too.

subith86 17 Junior Poster

the scanf at the end is to keep the program on the screen after it executes and displays the output..

Use getch() function defined in conio.h thereby you can avoid using scanf() to hold the output screen.

And before you proceed, you need to verify the sides belong to a valid triangle. If you remember from old school mathematics, the 3 given sides are the sides of a triangle only when sum of any two sides is greater than the 3rd side. 1, 2, 5 can never be the lengths of sides of a triangle.

Moreover there is no need for the last "else if". A simple "else" is enough.

The error that you made in your code, is clearly shown in the warning from the previous post.