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

Hi just wonder how I can use commandbutton ( caption Letter A) click event to read names from an random file that just corespond to letter A in to an listbox.

In the click event
1) open the file
2) Start a loop, exit loop on EOF
3) Read a line
4) If line starts with "A" add it to listbox
5) End of loop
6) Close file

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

OK, I'll break it down. Every time you enter any input, do you press the ENTER key?

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

writeFile = CreateFile(argv[2], GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); :
Are you opening this file for reading? If so, why GENERIC_WRITE?
Are you opening this file for writing? If so, why GENERIC_READ?
Are you sure you want to require the file to exist using OPEN_EXISTING if all you are doing is writing anyway?

Look up all these attributes and understand when to use them, and decide if you need them in this particular case. Don't just blindly change things and hope for the best. That's not how programming works.

Also, write a test program to test the one statement you are having trouble with. See if you can get it to work without all that other overhead.

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

I've made a mistake. I was not responding to the correct post. I therefore have edited my response above. You probably still won't like it. and you didn't help him with functions at all, so why are you complaining?

And I still don't hate you.

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

I guess if you feel disagreement is hatred, fine.

To me, disagreement is a learning opportunity. If you ask "why do you disagree" and try to understand the answer, you may learn something new. You can also explain why you disagree and maybe I can learn something.

But if disagreement means "I hate you" then there's not much I can do.

And I don't know you well enough to hate you. And you haven't said anything for me to hate.

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

Then you need to find some fonts compatible with Borland's graphics library.

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

Every time you enter any input, do you press the ENTER key? That key does go into the input buffer, ready for the next input. You need to clear it out.

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

Read the Member Rules and find out. You were asked to do so when you registered.

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

Get a random number modulus 2 to get a bit.

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

WaltP-First i would like to say that i used all proper standards and syntax

Yes, but that doesn't mean you should use the pass by reference to return a single value. You should return that value as a return value.

and moreover he hasn't told that he want to do it using function and so i thought to give him simpler solution so that he can understand and if necessary program acoordingly....

void getTemp (int kelvin) was in his code, so he did want to use a function.

I hate this....for no reason you dislike my post.....

We don't want people to post answers to problems the OP needs to figure out himself. Especially when the code is badly formatted and doesn't even work. Try running your code and convert to F. It fails.

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

I apologize that did not come out how it should have

Is this supposed to mean something?

My guess is your second command line parameter for the write file is bad. And it doesn't already exist since you are using the OPEN_EXISTING flag.

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

3 - and this is a big one.
You write:

getTemp(kelvin);

I understand what you want to do. But you do it wrong. It works just by luck.
You pass kelvin by value, ie. the compiler copies its value on the stack and pass it to getTemp. Normally whatever getTemp does it won't affect the value of kelvin in the function main. You take the address in sscanf and by luck it changes the value of kelvin in the main function.
You should do:

void getTemp(int *kelvin)
{
  scanf("%d", kelvin);
}

and

getTemp(&kelvin);

This is passing parameter by address, not by value.

No you shouldn't. For a function that passes back a single value, you should return the value. You should not overwrite the value passed in.

int getTemp()
{
  int temp;
  scanf("%d", &temp);
  return temp;
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Many of your suggestion assume too much in the environment of the user. It's also limiting to 64 bits -- assuming that's even possible for the user. These modifications will allow you to deal with any size binary value you choose -- based on the input array:

1) Don't use the %d format in scanf. Read the data in as a character string,

Correct -- use fgets()

2) All characters in the input string will be either '0' or '1'. Use the characteristics of the character values to your advantage. Subtract '0' from each character and you will be left with int 0 or 1.

Yes. Start at the beginning and subtract until you get to a non-1/0. This will, of course, be the end of your binary string, and your conversion start point.

3) You have a choice to make here. You can start at the end of the input string (the LSB) and work backwards, or at the beginning of the string (MSB) and work forwards. Each has it's advantages. Starting with the MSB is simpler logically. I'll illustrate this here In this case, the entire string will be processed before converting to HEX

Start at the end.

4) Initialize the output value to 0.

Actually, initialize the output value to SPACEs. You are going to load your HEX values into a string. Since you know how long the binary value is, you know how long the HEX value will be. Start an index

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

Each compiler is written specifically for the OS it runs on. The compiled program therefore runs only on the OS it was built on.

Standard C/C++ relates to the source code. All compilers should accept any C/C++ code that was written to the C/C++ Standard and output a working program.

Therefore, writing Standard C/C++ should compile using any compiler.

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

So the text "Has this thread been answered?" held no meaning. And the text just below it was unreadable....

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

So you don't think the error itself is worth knowing, just that the box itself jumps out. You probably go to the store and buy unlabled cans of food, too.

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

You mean none of this is explained in the help nor at the home page? There's no documentation at all? Somehow I don't believe that...

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

You were closer before.

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

Why don't you actually look at the values as you calculate them -- just to see if your calculations are correct. Output them. I assume you know what DD:HH:MM:SS you are expecting from the seconds you enter, right?

Also, it might help to actually use pencil and paper to execute your code by hand. That's the best debugging you can do at this stage.

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

You need to think about what you are doing and look carefully at the variables you are using. Are they the correct variables for each line?

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

Pass the midpoints in by reference. Load your values into them. They will be changed when you ret

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

What are those () after the return statements? I know you didn't learn that from your book.

You need to add prototypes for your functions at the top of the code.

Don't ask -- look it up in your index.

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

Neither do we. If it won't compile, it probably has errors. If it has errors, the compiler tells you what they are and where. Since we are not compilers, we need details.

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

No.
What they said is correct.

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

I would guess that it's because you have no data to display. Where is myarray loaded?

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

First post -- CODE Tags and formatted! Such a wonderful thing to see!
One tip - change your IDE to replace TABs with 4 SPACEs instead. Notice hoe the end of your code gets lost in line-wraps. It's also easier to read in general.

Your program as written should exit on 7, 11, 2, 3, and 12 as an initial roll. You have no loop to roll again as far as I can see. Lerner provided you with a good algorithm for fixing main()

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

In the function definition: void All_Grades::grade_set(class_percent)//needs to take class_percent what type is class_percent? Don't you need to specify?

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

Oh, 10 binary digits....

Add output statements at key points in the program to see what values are being set into what variables. When you see a value you don't expect, that's going to be a problem. Fix it and try again.

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

Ok. I understand now. Problem is there are many times, I couldn't get a satisfactory answer that I can understand .. Maybe it's just me.

Then explain why you don't understand and ask for clarification. Key is explain -- don't just say you don't understand.

By the way, just curious .. you guys getting paid doing this? :OP

No.

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

Your program only inputs 1 binary value. You can't get to 8-9 binary values without a loop that contains the input.

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

How many different answers are you expecting? If you get three different answers, which one do you choose? Doesn't having multiple answers give you more problems?

And if you only get one answer from three different sites, who just wasted the time of people on two sites? Why do you consider that a good thing?

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

What?!?

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

No, don't convert to decimal. It's not necessary, and it's harder. You can convert directly into hex.

Finish defining your char hexadecimal[17] array (and it only needs 16 values). Then start at the end of your binary and convert 4 'bits' into an integer. Use that integer to get the hex character. Ex:
You enter 101100101
you convert 0101 into it's binary value (5) then load the hex character into your hex-array answer.

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

We have no idea what you are talking about. Details and examples, please.

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

Moschops is saying you program the computer to do the same thing you do without the computer. What's your first guess? Make the computer to the same thing.

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

It also depends on the compiler, too. Most compilers can't do it.

In your case, I would guess it's VC++ something, so getch() would work.

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

Because using getline() as in this example terminates the input read once it hits a newline (by default), 'you have to make sure no extraneous input exists in the buffer prior to calling it'.????? For example, if you read in an integer, then a whole line, the user may enter 54 followed by the Return. The 54 would be assigned to the integer variable, 'leaving Return in the buffer'????'This Return would immediately terminate the next getline()call'why????

There are some input forms that don't read the entire line. If you use one of these to read an integer, it reads the integer only. It stops reading after all digits have been read and leaves the rest. If you enter 54 23 12[ENTER] and read an integer, 23 12[ENTER] is left in the buffer. If next you want to read the person's name, the getline() will read 23 12[ENTER] as the name. That's why you must clear the buffer.

'The getline() function discards the newline character that terminates the line.' Why does it do that???? So this newline will not be part of the string that recieves the entered value.

Why? Because it says so. That the way getline() is designed.

The getline() function takes an optional third argument that defines the stop character. By default getline() stops reading in when it hits a newline, but you could have it terminate be a # or whatever.

Yes.

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

No. What happened when you checked it using paper? When did you write down the *? Inside which loop?

Also, at your level of programming, you need to use more { and }. Put them everywhere -- around all loops, all ifs etc. Even the loops in the code you posted. You can then see for sure what's happening.

tomato.pgn commented: Stop spammong same message -1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you using pencil and paper to "run" your program and see what happens? It's only 4 lines of code. Certainly you can follow that much just to see what the code does.

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

It's obvious you skipped the entire chapter on using the variables in the class you defined. Try reading that chapter and looking at the code again.

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

You didn't set up the config files.

Assuming the bin directory is C:\Program Files\Borland\BCC55\Bin\ , create these two files in the bin directory:

BCC32.CFG
-I"C:\PROGRA~1\Borland\BCC55\Include"
-L"C:\PROGRA~1\Borland\BCC55\Lib"

ILINK32.CFG
-L"C:\PROGRA~1\Borland\BCC55\Lib"

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

Since this is a school project, and very obviously you haven't learned vectors, make an array of your class product and you can fill each product with your data.

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

What do you want it to look like? A line of * or @ could be used.

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

zgesv_ is a variable or function you tried to use but didn't define. Hence "undefined reference"

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

What keys -- all of them -- are you hitting when you answer the question? Isn't it n[ENTER] ?
If so, your code reads the n , correct? What happens to the [ENTER] ? Well, the next input gets it and does what it's supposed to do. Exit.

You need to clear out the input buffer after reading the first character. There's a sticky at the top of the forum to explain how.

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

Where is strdup() defined? How is it defined? It's not an ANSI function.

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

Explanation of task - check
Current code - check
Explanation of what you have trouble with - nonexistent
Therefore - requesting us to read your code, understand what you did, try to correlate it with the task list, and try to figure out what you don't understand, and finally tell you what you need to do.

How about you give us an idea what you need instead....

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

Ok, so I don't quite understand how the

srand()

function is used, (line 34 of main) in combination with the functions

rand()

line 48 and 49. Why do we need srand() in this program, isn't rand() enough?
thanks

See this and this

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

Code cannot do 2 things at once. I can only do one thing then the other. If you would stop being cryptic and give us the necessary details to understand your specific question, we would probably be able to help.

But this "I know what I'm doing but it doesn't work" gives us nothing to go on.

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

Didn't Dave answer you well enough 4 hours ago on the other site? Was there something you didn't understand?