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

If you are working with array[j] you need to update bday[array[j]]

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

You need to output the teens OR the ones value -- not both.

If output 00,20-90, output 0-9
but if output 10-19 don't output 0-9

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

hm,man this works BUT IT USES 100 CPU :S :S :S

how to solve it?

use Sleep :icon_wink:

You said:

I need simple timer that should not mess with the threads,and doesnt use Sleep().

What you wrore doesn't do anything but spin on the timer so it'll use whatever CPU is available.

But if you add this to the thread you need the timer, you'll do work. Then when the timer hits your 30minute mark, the timer code will execute once (if you write it correctly). Then the thread will continue as you need.

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

Read up on the function. Don't make invalid assumptions.

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

If you want 30 minutes:
Call time() to get the current time - say tstart
Add number of seconds in 30 minutes to tstart.
Call time() every cycle -- say tnow
When the tnow >= tstart, call function2.
When function2 returns, reset tstart

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

Yet another way to keep the count:

Have an array of 366, maybe call it bdays[366] (one extra to skip day 0)
In your code, array[] keeps track of which b'day each person has...

So, if array[0] has a b'day on 122, increment it: bdays[array[0]]++; You've just counted that b'day.
Next person's b'day on 68 - bdays[array[1]]++; etc.

When done, if bdays[5] == 3 then 3 people had b'day on day #3.

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

error LNK2028: unresolved token (0A00000F) "extern "C" int __stdcall GetUserNameA(char *,unsigned long *)"

Where is GetUserNameA() defined?

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

First thing I see is using C-style headers and C input. Get rid of all the C headers ( conio.h, stdio.h ) and stick with iostream . With that, don't use _getch() . Use C++ input commands. math.h should be cmath , the C++ version.

Fix that and if still a problem, describe in greater detail what is happening.

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

hey i have done the use case for this prob stmt.

wat u ve done has lots of mistake..


if u want den let me knw........ll mail u d diag................

Very bad start....

Do not post any email addresses on any forum.

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

Repost your code. It got lost when correcting the post -- it's not a Code Snippet.

What was the value of y[0] before? What does it change to?

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

Don't cross post

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

I'm sorry I didn't see the checks that were in place. My eyes were faster then my brains. This code is fine i though I saw something different.

Been there, done that. Gonna do it again, too, unfortunately :)

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

you are using cin >> val; which will cause an infinite loop to occur if if something other than a char is entered.

Other than a char ? Like what? If the input requires a char , what can you input that isn't a char ?

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

I agree with Vernon and Dave.

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

Hi frens,
I couldn't compile this solution code given by my university on visual studio.Visual studio works fine with other C++ files.

Why not? Does your machine crash?

When asking for help always give enough information so someone that is not in your class or can't see your screen can understand the problem. Full disclosure -- what happened, what went wrong, what was supposed to happen? At least.

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

If fgets() doesn't work, I can only think of reading a character at a time..

But, you should see this about scanf() and strings.

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

Look in the help index for Date and/or Time

you mean this?

Private Sub Form_click()
Print Date; Time
End Sub

I don't understand this: when form is print i get to see the day & time events took place

What Help index did you look in to get that? If that's what it says, change to Visual Basic. That's the help index I was thinking of.

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

My assignment is to compare the files char by char... believe me i wouldn't be doing it this way if i didnt have to. we have to report the line the files are different so using getline makes that part easy.

Another option then is to read the files one character at a time. When you read a \n, increment the line count.

I wouldn't change to this now, but next time it's something to consider.

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

Look in the help index for Date and/or Time

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

One thing I'm wondering is if you are reading the entire line from both files, why are you checking character by character? Couldn't you just compare the lines as read? if (s1 != s2) You are using strings, which can be compared with ==

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

I am not attempting to insult you.

Waltp i think every person has a common sense kind of thing. As you can see that he has appriciated my answer by saying "Thanks 4 that garbage char prob". I just try to solve his problem of reading char by char. It is easy to reverse a buffer as compared to a file.

As Dave points out, and using your terms, common sense dictates that if someone says "Thanks 4 that garbage char prob" and you never mentioned garbage char prob, he wasn't thanking you. Maybe?

I also stated "This is the second bad info I've seen you give in 2 posts." Anyone that seems to habitually give bad information should "think before you answer questions." This is also "common sense".

Please notice that your reputation indicator is not green. This is indicative of something. Maybe "common sense" is not that common.

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

Also your if clause should be like this:

If dbltotalaverage >= 90 Then
                txtgrade.Text = "A"
            ElseIf dbltotalaverage >= 80 And dbltotalaverage <90 Then
                txtgrade.Text = "B"
            ElseIf dbltotalaverage >= 70 And dbltotalaverage <80 Then
                txtgrade.Text = "C"
            ElseIf dbltotalaverage >= 60 And dbltotalaverage <70 Then
                txtgrade.Text = "D"
            Else
                txtgrade.Text = "F"
            End If

Not really. This should suffice:

If dbltotalaverage >= 90 Then
      txtgrade.Text = "A"
   ElseIf dbltotalaverage >= 80  Then
      txtgrade.Text = "B"
   ElseIf dbltotalaverage >= 70  Then
      txtgrade.Text = "C"
   ElseIf dbltotalaverage >= 60  Then
      txtgrade.Text = "D"
   Else
      txtgrade.Text = "F"
End If

The second part is not necessary because the comparison preceeding takes the < into account already.

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

Yeah, I know what you mean. They do exist. You just haven't found them. I just don't know any links. So Google might help.

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

Instead of reading character by character use "fread" to read more than 1 character from file at a time. And then use "fwrite" to write them to the output file.

You can also use "fgets" to read a file line by line. Because "fgets" terminates reading on "\n" (new line escape sequence).

And how does this help the OP write the "output file in reverse order" better than what he's done?

Please think before you answer questions. This is the second bad info I've seen you give in 2 posts.

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

void main is also fine

void main is NEVER fine... Read this.

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

I was stuck and sent my instructor what I have had so far....she gave me more advice and here is my code reworked...however I am still getting errors.

You're still getting errors.... Hmmmm, my psychic powers are picking up
Error E2265 x.cpp 2: No file name ending
Error E2062 x.cpp 47: Invalid indirection in function main()
Error E2451 x.cpp 53: Undefined symbol 'r' in function main()
*** 3 errors in Compile ***
You forgot the > in the include line on line 2
You have too man *s on line 47
The variable r was not defined when used on 53

How'd I do?

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

#1: Bad definition
File contents:
LYRTTE\n
MVTRWE\n

All lines in the file end with \n, or value 10 char line[6]; // Only 6 characters defined

while (fgets(line, sizeof(line), fid)!=NULL)  // Read 'LYRTT' from the file and add the required \0 to fill out the 6 characters
{                        
    fscanf(fid, "%s", &line);    // Throw away the data just read and read the final E, \n.  store E \0  in line.

Also, on the fscanf() you don't need the &. And why use that when fgets() does the job better? See this.

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

Yes Jonsca, I have already read that and I was wondering if there is one single function within standard library.

No.

I saw somewhere string::Substr() and I'm trying to check if that is what I want.

That is one way to do it.

Anyway the bad of C++ is that there is no official Manual to download and look like other languages (PHP, JAVA, PYTHON et al)

There is, sort of. It's called The C++ Standard. But most any C++ 'manual' on the web will give you the info you want.

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

I am done wid the ouput but iam not able to do the Vertical lines "|".. can anyone help me.. wid the logic. I am doing preorder...

wid? Is this some kind of slang in India?

Since I can't follow your program even with CODE tags, and your explanation is vague at best, all I can say is keep track of your indenting and output 3-4 spaces followed by '|' for each indention level.

And if you want to get good help, format your code so we can read it.

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

Buffered output is probably the problem. End the cout line with flush to empty the buffer immediately.

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

You are dealing with floating point numbers. .99 probably is stored as a close approximation of .99, very close. But not close enough. Same with all the other values. Therefore, you have a little wiggle in the values and probably end up with something similar to -0.000000001 as an answer.

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

I don't see anything glaringly wrong, but since you didn't bother to show us what you are reading, what should have happened, and what did happen, that's as far as I'm going to go with it.

Remember, the more details you give, the less we have to guess -- and guess wrong.

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

Nathan is right. Change the for statement. You can better write the for as for (;!ifs2.eof();) which is really a while() Also, as he says, you read off the first line of file 2. Then

for( int i = 0; !ifs2.eof(); i++ ){
    getline( ifs2, s2 );  // Read line from file 2

    if( !ifs1.eof() ){
      getline( ifs1, s1 );  // Read line from file 1

      c1 = s1[i];       // get the first characters of each line
      c2 = s2[i];
      if( c1 != c2 )    // compare the first characters in each line
        cout << endl << "Files differ at line" << (i + 1) << endl;
    }
  }

So, if the first character if each line matches, the files are the same.

Here's why you don't want to use .eof() -- feof() in C is the same as .eof()

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

As Narue implies, the !! is 'converting' the integer value to boolean.

The !x equates to true/false. The additional ! reverses the value. So if x = 23 (which is an implied true), !!x is 1 (strict true).

If you need a strict true, it's obviously useful, but if b is a boolean type, b = x; seems to accomplish the same thing.

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

Ah, just realized than instead of hardcoding every value, I could just go:

blocks[rows][cols] = (readLevel.get())- 48;

BINGO!!! :icon_mrgreen:

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

You need to read the input as characters
Test each character to make sure it's a digit
If so, convert the value to int/float.

How would I do that? I'm new with c.

Do what?
1) Read characters?
2) Test characters?
3) Convert characters?

If 1, don't bother trying it yet. Come back to this in a couple weeks and you'll be able to do it.
If 2, wait until you learn loops. Then come back to it.
If only 3, look up string conversion functions in your book. They start with ato* and str*

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

Your first post contains your answer:

Instead of reading the value I want into the array, instead it read the ascii code. In other words, instead of reading 0 into the array, it reads 48.

If you have 48 and wanted 0, how can you get there?

What happens if '1' is the first thing read? Or 8? Is there a pattern?

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

Try this version of your code:

#include<stdio.h>

int main()
{
    int i=getchar();
    while(i!=9)
    {
         if (i >= 32 && i < 127) 
        {
            printf("The character '%c' (%d) was entered\n",i,i);
        }
        else
        if (i == 10) 
       {
            printf("The ENTER key (%d) was pressed \n",i);
       }
        else
       {
            printf("A weird character was pressed (%d)\n",i);
       }
        i=getchar();
    }
    printf("%d",i);
    return 0;
}

Does this help?

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

Read very carefully. Turn off the TV, turn off the radio. Study this post.

When you enter anything into an input, each and every key you press (except the obvious CTRL, ALT, etc) is a character. Including the ENTER/RETURN key! You type in a and hit ENTER, you have 2 (two, dos, deux...) characters in the buffer.

You now use getchar() . How many characters does it read? 1 (one, uno, un). You output the character read, you get 97. That leaves the ENTER in the buffer.

If you exit, you leave that ENTER in the buffer. You loop, the getchar() reads the ENTER. You output the character read, you get 10

Any more questions? If so, you'll just have to believe us.

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

You need to read the input as characters
Test each character to make sure it's a digit
If so, convert the value to int/float.

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

What's in the file -- a text '0' or a binary 0? .get() only reads exactly what's in the file. It doesn't translate an ascii digit into its binary equivalent. You need to do the conversion.

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

So? You leave the \n in the buffer and exit? What does that prove? Try typing "abcdefgh". What happens?

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

Maybe this will help

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
/*part of solution by WaltP */
#define UINT_BITS ( CHAR_BIT * sizeof(unsigned int) )
#define rotateleft(x,n) ((x<<n) | (x>>(UINT_BITS-n)))   
#define rotateright(x,n) ((x>>n) | (x<<(UINT_BITS-n)))

Be more careful quoting. I never posted in that thread nor did I write that code.

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

Yes, except for using .eof() See this. feof() is the same.

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

@adnan
hey ive tried your code and it works...
but it is a different code...
this code is somewhat like

The idea is to use his working code to understand what he did. Then use that understanding to write your code. All you seem to be saying is "that code is not exactly what I'm trying to do, so write what I need for me."

WaltP?

I understand about strtok coz it is use to search char within the string and make a token from what and where the delimiters place..... If you some idea about this show us but please don't blame me of low understanding because im a student and actually a newbie about string. Hope u understand, i'm not asking help to do my assignments i just want to understand about it...

Of course I understand. I'm not blaming you for not knowing. I'm blaming whoever told you about strtok() and didn't explain it to you. What I am saying is you don't need strtok() at all.

I really can't help you because when I tried you ignored what I said completely.

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

Add tcclass.lib to the compile line.

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

Cant find it!!!!!!!!!!!!!

hmmm...i knw ...i misd it...

but i still cant find....
plz guyz reply wid a code...i have a submission due tmrw...

Cut with the baby talk. This is an adult forum.

This will help -- click here

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

Enter text in the textboxes
Select the records from the database and look for a match.
If found, open the new form.

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

Don't you have to resize the picture control? Try changing picture1.width and picture1.height instead.