WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

For the 3rd f'ing time, WHAT DID IT GIVE YOU????

And look up the fopen() function for the proper use of the 2nd parameter.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

TC1 seems to work on Win7. At least the compiler executes.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

OK. Whatcha need?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Another question about strtol. If I have an double that has two decimal numbers, such as 941.59, and I want to set the .59 to an integer with the value 59, can strtol be used? If not, how could that be done?

If you are asked to do it on paper mathematically, how would you do it?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Maybe you and MKS200 should get together...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's obviously code they were given by the instructor, and they both want us to finish it for them.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I just know that the values of byte0,byte1,byte2 and byte3..
But please explain me how to fetch these values??

What have you tried? What did it give you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Compilers? No way WP ;)
They are IDEs and some of them bundles compilers
MINGW|MSVC Compiler|Open WATCOM|Digital Mars et al

I would suggest CodeLite or CodeBlocks. Simple and beautiful IDEs that can be used with MINGW (GCC) and MSVC as well as others

If the IDE bundles a compiler, it can produce code. As far as most people are concerned, that is a compiler. Don't be so anal...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What have you tried? What did it give you?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

There is not enough information to even make a bad guess. There is absolutely no context given.

Your best bet is to use your debugger and find out what line your error is on, then look at all the related values.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As jbennet said a year ago when this thread was resurrected then:

Was there a point to awakening an old thread?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Yes

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello all can you help me up with this guys.. i have this application with a product id which is in Hexadecimal format..wat i mean is an alphanumeric format.. and it is asking for a product key.. how can i suppose to know the product key?

can you give me some idea how to calculate this or convert this so that it will come up with the right product key..

Product Key = Product Id

Advance thanks to u all..

You look at the packaging that came with the product when you purchased it. If you didn't purchase it or you did and the key wasn't with it, it is a pirated copy and therefore illegal.

Please read this

Thread closed.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Open the file with "wb". "w" is text by default.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Search for the proper software. If you want to do it yourself, check into some universities that have curriculum for computers and vision analysis.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

apologize for the missing code tags and in regards to the size we are required to minimum of 1000 lines

That doesn't mean you have to post every single line, does it? Just post the section that you are having trouble with.

And next time, just EDIT the previous post, don't repost another 1000 lines. Or better yet, use the PREVIEW button next to the SUBMIT button. You can verify the post looks right beforehand...


As it is, I'm not searching though all that code for your 300 problem without a road map (a code map :icon_mrgreen:). My guess is when you enter a value over 300 you don't clear it before returning.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Only if falling out of the function's bottom is not the place for returning.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

By calculating it? At least that's what I'd do.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Using the Free Borland 5.5 command line compiler?

Borland 5.5 is not a Turbo compiler. Turbo stopped at ver 4.

@aianne
I would recommend you scrap that compiler (which supports non-standard header files) and get yourself a new one that supports C99
I would recommend Code::Blocks.

And how does that help with polygons, squares and circles? Does CODE:Blocks even have graphics? Turbo does.
You need to understand the persons needs before suggesting things they can't use...

You don't know WTF you're talking about!

Calm down. When most people here see the name Turbo they have a knee-jerk reaction. They don't bother to think that it just might be possible that TurboC++
- is actually best for the task at hand (as you point out)
- is the instructor's pet compiler because he's a hack
- has all the non-standard functions required by the hack that is teaching the class.

It's not their fault (the knee-jerkers). They just feel that using 20 year old compilers is a bad thing*.

*it kinda is a bad thing, but with TurboC you can get an understanding of the graphics concepts that you can't get with most other compilers. And without adding and linking outside products.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

can u give me some advice because i really need it ......

Thxxx

First, figure out what you want to do.
Next, write down all the features you need in the program
Start designing these features -- one at a time. Use as much detail as possible.
Pick the most important details and convert the design into code.
Desk check the code carefully (run the code from your paper using a pencil)
Then, for the first time, type the code into the computer, compiling and testing often.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Why are you using a while statement in a recursive function? It is going to cause a major problem on the return rewind. Turn it into an if .

Also, if x is negative, is x/-10 negative or positive?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Where are they actually declared? I see where you set them to values, but you don't declare them anywhere like you did month day, year.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The compiler can't possibly do that. The conversion happens at runtime, by crt0 or something else.

Sure it can. On the proper system, when the program returns 0 to 'the system', the compiler adds exit code to the program to convert that 0 to the proper value before returning control to the system. It's code added between program code exit ( return 0; ) and actual program shutdown and system re-entrance.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Dear Friend,

But are you getting my point or not? As i want to see entire output on my screen. How it will be possible, that i want to know. Even if with DOS prompt i am getting same thing.

Can anybody help..?

Thanks and regards

Get a new monitor that has 255 lines on it.

Or remove the \n from the printf() line.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

is this

if (buf == "TIME") {
    printf("Time: '%s'\n",msg);
}

the proper way to compare strings in C?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

str is a pointer to a character array.
Assume char *str = "ABCDEFG"; The first character in the array, 'A', can be represented as *str -- contents of str *(str+0) -- contents of 0th element of str
Expanding this last one, *(str+3) -- contents of 3rd element of str: 'D'

Therefore, the for loop tests the character at (str+i) to see if the end of the string has been reached -- the ending \0 count[*(str+i)]++; uses the character at (str+i) as an index to increment a value in count
If i = 0, it increments count, or count[65]
If i = 4, it increments count, or count[69]

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don't see where you even read my post, let alone tried to answer my questions.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is it defined as?
Where/how is it used?
Does the use and the definition match?

And please format your code. If it gets any longer and more complex, we won;t be able to follow it. If you want more help, you do want us to be able to read it, right?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If I was writing this routine then I would either cut out the call to atoi and the while loop and put in a call to strtol or I would cut out the call to atoi and and expand the while loop to do the calculation of the value as well.

Ideally, I completely agree with not using even atoi() , as your code demonstrates. When you write the parsing, you are in complete control. You aren't subject to the whims and potential errors in the unknown code from ato?() nor strt??() . This way you control all the bells and whistles -- and warts -- of the input. Converting numbers is trivial, so why use a predefined function anyway.

Actually I just realised nearly bullet proof it is because absolutely anything could appear after the last number (same goes for my routines since they are based on yours) once this routine has successfully parse 3 numbers it assume success no matter what follows.

I did that on purpose. Allows for 12/10/2005AD . Another trivial test can weed that out if you don't like it.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Without the input, calculateSalary() sounds like a very useful function.

In my opinion (other opinions welcome), the functions in a class should generally do one thing only. That one thing might be complicated, but still only one thing. If it inputs, that's all it does. If it calculates, that's it. Keep the class functions primitive.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ahh, forget it...

jephthah commented: :P +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I moved into my setSalary member function definition because this is supposed to be object oriented design so I assumed that I should not leave a do while loop out in my main function and that it needs to be under an object in class.

Bad assumption. The setSalary() member function ideally should do only that -- set the salary. No input. No output. No calculations. Just take the parameter and load it into the variable member. This is true for all primitive functions like setters and getters

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I dont like using system("PAUSE") and I changed it to cin.get() but I noticed that cin.get() isn't working on some of my programs then I use system("PAUSE") then it worked. But for this program cin.get() is working.
Thanks for your effort.

That's because the other programs probably left the input buffer dirty. Carefully check your code and look for inputs that will leave \n in the buffer -- like reading a single character but not the ENTER that was typed in with the character.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what is this mickey mouse bullshit, walt?

you go and pull my posts out of the middle of another thread, and use them to create a new thread in my name.... and then Double Post it, too?

you have too much time on your hands to be getting worked up into a state of such pettiness.

No, I'm moving the useless crap out of a thread because it is of no use to the OP. Note I also left your post in that thread, too.

I am policing the threads as per my position. Sorry if your post was the first to be moved but the previous posts didn't warrant being part of the discussion.

And if it was pettiness, I'd just delete your posts and infract you. But instead I let the discussion continue away from the thread it was cluttering up. Not a good idea? Why not? Explain.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

now if you need to preface your calls to ato? with some routine that identifies whether or not it's a number in the first place, you've kind of defeated the purpose of having an ascii/string-to-numeric converter, yes?

Not if I'm parsing a special format -- Date, Time, SKU, Phone#. To blindly pass an unknown string into a converter is bad form. Verify the syntax. Then you don't have problems converting.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is this nearly bulletproof?

/*  Does not verify date components (month <=12 etc), not 
    the purpose of  the task. 

    Handles 3 number fields (a date) separated by / - . and SPACE
 */
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>

int isSeparator(char ch)
{
    if (ch == '/')  return 1;
    if (ch == '-')  return 1;
    if (ch == '.')  return 1;
    if (ch == ' ')  return 1;
    if (ch == '\n') return 1;
    return 0;
}

int main()
{
    int date[3];
    int i;
    char buf[200] = {0};
    char *p;
    
    printf("Enter date: ");
    fgets(buf, 200, stdin);
    
    p = buf;
    i = 0;
    while (*p != '\n' && *p != 0 && i < 3 )
    {
        if (isdigit(*p))
        {
            date[i++] = atoi(p);
            while (isdigit(*p))  p++;
            if (isSeparator(*p)) p++;
              else              break;  // non-date character
        }
        else  break;                    // non-date character
    }
    if (i != 3) printf ("Illegal Date Format");
      else
      {
        printf("%2d/%02d/%04d ", date[0], date[1], date[2]);
      }
    return 0;
}
tux4life commented: Nice code :) +8
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i like how some people seem to assume that they can somehow guarantee the format and content of strings being input by an end user or some other uncontrolled process.

the fact is, nobody ever knows for certain what will wind up being passed in as a string argument. data can be corrupted even if everything else is "guaranteed"

that's why you need to use strtol() to convert numbers, rather than the non-error-checking atol/atoi

and strtok() is powerful enough to be able to handle multiple types of token delimeters. so, when combined with even a modest amount of error checking, strtok and strtol can make a nearly bulletproof string-to-numeric converter.

You have brown eyes, don't you?
My input is bulletproof and I've never used any strt??() functions. Get off your high horse and accept the fact the there are other ways than your pet ways. I'm not saying you shouldn't use strt??() functions, I explained why I don't. You, in the other hand say you can't use ato?() which is crap.

We've been here before, J. I really don't need yet another PM apologizing for being hardheaded. Become a real programmer and embrace other opinions. Don't use them, but don't diss them either.

Not entirely bullet proof since it will interpret my half a shopping list as a date

Enter Date String : 1)Fish.2)Chips.3
   month : 01
   date  : 02
   year  : 2003

Verifying input involves verifying no additional garbage was input too.

Cowandchicken??

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I do not care about strtok() much. It doesn't work with read-only strings like the literal "this string", since it has to modify the given string to token it.

And that's why I wouldn't use it at all. How do you know the user entered 2/5/2000? Maybe he entered 2-5-2000, or 2.5.2000. If you have to do that much verification, you might as well use atoi() because you already know what is in the string. Or better yet, convert the values yourself like I suggested and actually learn something :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What jephthah says is correct, but by not passing "cowandchicken" into atoi() you won't have a problem.


You need to look at the characters anyway. This is the verification phase of any conversion. Make sure you pass digits at the front of the string and you're fine. Anyone that would blindly pass a non-verified string into a conversion function gets what he deserves.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

WaltP: please don't put words into my posts that aren't there. I'm saying no such thing. My comments were intended for Jay.

Such as? Only thing we have a disagreement on is Random being a reserved word. It isn't.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Same crap. Except you added it in TWO places this time. As long as count < size, the loop will never exit. What cold possibly cause that in you new and improved code?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

With thanks to Firefox for its ability to highlight the word salary

Not the point. And what if the variable name was salry?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree with David (except there's only one sentence :icon_wink:)

The memory aspect actually is more confusing, so don't mention it. It seems immaterial to me in a description unless you are describing the lowest level of programming.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

He means "Never write code straight into your editor (from out of your head) without first writing it on paper and desk checking it."

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Recursion is not an answer to your problem. Consider carefully the first thing FBody said.

Call the function (since you already made it one) and instead of calling the function again, just put the function in a loop.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
[B]random[/B]   Macro that returns an integer.
 Syntax:
   random(num);
   int random(int num);

Not every compiler may have this, but some do.

Sorry, that doesn't cut it. If not all compilers (only TurboC as far as I can tell) have it, it is not a reserved word. And any use as a variable will override the macro definition.

Or are you also implying that when using DevC I can't create a variable named clrscr or gotoxy because it's defined in TurboC3?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You'll really have to scan the file for the line. There's no telling where any specific lines start.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Have a beer for me. That'll do....

jonsca commented: Does that go for anybody? ;) +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Go to a local computer shop that's been around for years and have them build one for you. They will provide service you can't get from the Big Names.