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

One more suggestion -- format your code properly and wayward braces will no longer be a problem. Don't indent 3 tabs then next line 1 tab, then 2 tabs.

Your first brace should be far left and every line after indented 4 spaces. Each and every { indent 4 more spaces sterting with the next line. When you get to a } unindent 4 spaces, then add the } on a line by itself.

Then your code is easier to read:

void Look::printShipPos()
{
    if (checkFlag > 0) 
    {
        static int shipPos = 0;

        cout << shipPos << "_shipPos 1"<<endl;
        shipPos = shipPos + 228;
        cout << shipPos << "_shipPos added"<< endl;
    }


    if (shipPos == 228) 
    {
        std::cout << "French Polynesia [Out of Transmission Range]"<<endl;
        else if (shipPos == 456){
        std::cout << "Maui, Hawaii [Out of Transmission Range]"<< endl;
    }

    //---------------------counter for fly-over access
    checkFlag++;
    cout <<checkFlag<< endl;

    return;    
      
}
mattyd commented: TY :) +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

From Tom Lehrer's Bright College Days:

Sliding down the razor blade of life

Ouch! :eek:

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

With your desktop active hit F3. This will allow you to search your system for a file.

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

I'm have trouble getting my area/volume progam going on a circle,cylinder,sphere,cone
One with out a menu and onwe with a menu. Thanks for all your programmers help. This is a great site for help.

We're kind of low on psychic helpers here. We really need some details. Not a clue what problems you are having if you don't tell us.

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

Hi guys!!!

HI!

Is it a good idea to attach my program with this msg???

Generally, yes. Be sure to read this about Code Tags.

Also, in English, sentences end in a period which is then followed by a space. Don't write them like a web address.

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

HI,

Actually I have a problem since I cant read properly a file from visual basic.
The file is generated in Binary but when I open the file appear this content
:

8ø@ Lø@ ÀOø@ ÀOø@ @Mø@ ÀOø@

I dont know how can I convert each value. As you can see each value is separated for @, so I need to read each of them.

I dont know what character code is used in this file but I would be greatful if someone can advise me.

Many thanks

Since we don't know how you are opening the file, what cah we suggest? Maybe it would help to post some code?

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

Since you declared the variables as integers, you could convert the string values to integer by using cInt function. try like this

num1 = cint(txt1.text)
num2 = cint(txt2.text)
num3 = cint(txt3.text)
num4 = cint(txt4.text)

avg = cint(cint(num1 + num2 + num3 + num4) / 4)

this should work without any error.

- bls

Convert all the numbert to integer, then add them and convert that number to integer, then divide by 4 and convert that to an integer. Isn't that a little overkill?

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

You keep asking the same question over and over. Unfortunately, without knowing what the data looks like (as all responses have tried to ascertain) there's not much we can suggest. Figure out what the data looks like to the program, then the way to count the pulses will become apparent.

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

Also, haven't youe ever heard of formatting your code? It's unreadable without proper indentation.

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

Forget the remove_newline() function. Make it simple:

fgets(my_string,80,stdin);

    int string_length=strlen(my_string);

    if (my_string[string_length-1]=='\n')
    {
        string_length--;
        my_string[string_length] = 0;
    }

    if (my_string[string_length-1]=='?' || 
        my_string[string_length-1]=='!' ||
        my_string[string_length-1]=='.')
    {

Also, you can use cout to see what's happening. Display the character you are testing to see if you have the correct one. If it's not, check your code to see why not. cout is a good debugging tool.

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

Thanks for the info.

I guess it's the story of my life. Always at the end of the line.

When we're clearing the swamp, I for one want someone else's butt between me and the alligators...

Oops, did I just type that out loud? :eek:

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

Each character (letter, number, punctuation) has a numeric value. That value can be used as an index into an array of counters which you can increment for each character you read.

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

Please ask a full question. What do you need now? Do you have any more code?

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

Umm ...whats wrong with what I posted before?

Well, maybe:

* how do I extract the isalpha() do I use another loop ...
* where to i make sure the two letters being compared are not case sensitive...
* where I would include a provision for the comma?
* i'm going to leave out the termination I just don't think it is necessary....
etc

and your code still doesn't work

I know I'm being lazy but I don't really wanna go through the motions right now .

And how is this incentive for us to help you further? We aren't being lazy... :rolleyes:
Sheesh!

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

OK, it's time to back up and (sort of) start over. I haven't gone thru all your code, but you seem to be getting lost trying to solve 5 things at once. You never get anywhere that way.

Keep what you have because you can probably use most of it. Let's just rearrange stuff and do one step at a time.

#1:
Start with a new project.
Write the input portion of the code.
Input a string.
Output the string
When the string input and output are correct, move on, but not before!

#2:
Add the test whether the last character of the string is correct.
If not, do what you think you need to do.
Look at what you already have and use what you can.
When you can test the sentence correctly, move on, but not until!

#3:
Copy the input into another string character by character.
Copy only the characters you want to test as a palindrome.
Do not copy characters that aren't palindromish (space, comma, etc)
If you use string you should be OK. If you used char be sure to add that ending '\0'
Print out what you copied. When this looks correct, move on, but not before!

#4:
Add the ability during the copy to convert all uppercase characters to lower case.
Print out what you copied. When this looks correct, move on, …

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

Seconds would be the best for my needs...

Then all you need is the function time()

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

This works:

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    char *t1 = "1234567";
    int  mm,dd,yy;
   
    sscanf(t1, "%2d%2d%d", &mm,&dd,&yy);
    cout << mm << " " << dd << " " << yy << endl;
   
    return (0);
}

The other oprion is stringstream I suppose.

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

I may get grief from C++ afficianados but printf() makes it very easy to align data into columns. And it is C++.

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

Dumb question: I don't see the isalpha() being utilized in the final solution yet the program ignores spaces. Are you sure thats what he used?

Not a dumb question. And no, he didn't use it. But you might as well because it's easier.

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

For a while there, I thought this was going to go the way of the bunsen burner when a statement is twisted to illogical extremes

Yeah thats the main problem with these MS guys, they just do whatever makes them $$$$.

1. Hmmm. So you're in this for the love of it? Money's not an issue in your life, at least at this time. Student? Independently wealthy?

I almost jumped into the fire. Glad I waited... :)

I guess the only thing that still bothers me is the concept that systems development is more challenging that application development. It's different parts of the same horse, but I can certainly trade stories of complexity and sheer technical prowess over an impossible problem with the best Sys Prog. Again, not better, just different.

Very true. One has to be careful when compareing something that's relatively unknown in their universe to something they know well. I'm a software engineer with a lot of applications background but not in what's commonly known as Application Programming. I've stayed away from AP for the most part because of my perceptions (right or wrong) of that particular sub-field.

I do want you to understand that telling new programmers that applications development is not challenging is a slanted view, based upon your hard won knowledge of systems programming.

Extremely good point. It's like choosing the West Coast or the Midwest. What do you like better, earthquakes or tornados? ;)

...and I'm glad to be part of the community …

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

Okay, I will try that.


Thoguht about it:

Why would we be going backward in the loop? I want to shift the values to the right.

What I want ..

a[2] = a[3] <<First loop iteration
a[1] = a[2] << Second iteration

OK, try this. Seriously....

Take a piece of paper. Cut out about 20-30 squares from it.
Now place all but one in one row on a table in front of you.
Now read in a string by writing a sentence, one letter per square, starting from the far left. Don't make the sentence long enough to fill every square. When you end, after the last square you wrote on, write "EOS" to indicate the End of string (\0). That square is part of the sentence and must be there.

Decide where you want to add a space and place that extra piece under that letter (next row).

Here comes the problem. Using only two fingers, moving ONLY one piece of paper at a time in any direction, how would you make room for that blank without destroying the sentence.

When you figure that out, decide what you just did and how to translate that to code.

I've used this technique for complex array and matrix manipulation and it works really well in debugging code, too.

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

For a well detailed and excellent algorithm see HERE.

Thanks, S.O.S. :o

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

Can anyone point me in the right direction to how you can add highlighing to a source code text editor.

I don't know what language it's going to be written in. Java or c++ perhaps.

Thanks in advance.

I use VEdit (vedit.com). It can handle many languages, and if it doesn't handle yours, someone in the VEdit community will be able to whip one together. It's a very powerful and flexible editing system.

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

Thank you to all of you!
I made a mistake, missed the line "and just repeat that three times" which Bench posted, or I could understand it earlier.

Really!?!? Then maybe instead of wasting 6 hours, if you had just posted your code, it could have been corrected in an hour.

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

I've put up some posts about the programming tools that I am currently using. So far, no takers.

This makes me wonder what people who know what they're doing are using!

I generally use VEdit as my editor and Borland 5.5 as my compiler. But if the compiler I decide to use has an IDE, I'll generally just use that.

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

You know, you could just keep adding to the same thread and make a psuedo catalog of these things... ;)

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

Hi There,
I am trying to open a txt file with no header using vb6. my problem is that it's converting the first record as header. how can I solve this problem so that my first record will stay. Below is my code:

Private Sub ccommand1_Click()
Dim cnn As New ADODB.Connection, rs As New ADODB.Recordset
cnn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\temp, "", """
rs.Open "select * from file1.txt", cnn, adOpenStatic, adLockBatchOptimistic
rs.MoveFirst
MsgBox rs.Fields(0) '2nd record
rs.MoveNext
MsgBox rs.Fields(0) '3rd record
rs.close: cnn.close
End Sub

thanks in advance.

newvbguy

Why so complicated? Just open it using text-file functions:

open "file1.txt" for input as #1

Look up examples in the help system

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

Hmm.. I think there is some kind of misunderstanding here Mr. WaltP. His requirement is that the palindrome should be case insensitive as well as "ignore whitespace characters".

No misunderstanding. My algorithm does exactly that.

While isalpha(str[ch1]) is false: 
    Increment ch1. 
    Return if ch1 > len.  
    -- pass back true or false, you get to figure out which.
...
If LowerCase(str[ch1]) == LowerCase(str[ch2])
    call palindrome() again with ch1+1 and ch2-1

Which says

While the current character is not a letter, 
    go to the next character
    verify we still have characters still in the string
...
If the two characters converted to lower case are identical
    call the function again with the next and prev characters

Trying to loop through the whole string to ignore whitespace characters is not feasible, would jsut result in reinventing the wheel when we have good inbuilt functions to handle such kind of situations.
strtok is just the kind of thing we need here IMHO. Comments are welcome.

It's perfectly feasible. That's what a palindrome parser does is test characters, not tokens. Please explain what is not feasible about my post.

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

Notorious

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

I am working on an assignment to get an intiger from user, find all prime numbers smaller that it, and show all of them which dont contain a '1'. for breaking the integer into digits, I am using " x / 10 % 10 " algorythem, but I as it becomes a double , I cant use % with the double. and I dont know how to cast the double to integer before calculating %. thx for your help.

So you are dealing with integers, and prime numbers are by definition integers, why are you using doubles? There should be no doubles in you program. So don't use floating point at all. Just use ints and the % works fine.

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

Hmmm:

  • There are 0 people in the U.S. with the first name Walt.
  • This name is not found in our database, this means the name is relatively uncommon.

I tried it with Walter and it found me. But my brother is non-existant. Never liked him anyway...

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

My first reaction is why bother with strtok()? This is a simple program of characters, not tokens.

Next, C has a function called tolower() and toupper() that will return the character passed in as an upper or lower case value. Good for comparing case insensitive values. It also doesn't affect non-alphabetic values.

Third, if all you are concerned with is letters, the function isalpha() is ready made for you. If letters and number, it's isalnum().

strlen()
will return the length of the string to it's end, not to where you want to stop, so taking the string length in the palindrome() function is not doing you any good.

And using gets() is a recipe for disaster. Best to convert gets(x) to fgets(): fgets(x, 50, stdin); My take on this is palindrome() should take 3 parameters
1) The string
2) Index to the first character in the string
3) Index to the last character in the string

Then palindrome(str, ch1, ch2) can process the string in this manner:

Set len to length of str (so you don't run off the end of the string)
While isalpha(str[ch1]) is false: 
    Increment ch1. 
    Return if ch1 > len.  
    -- pass back true or false, you get to figure out which.
While isalpha(str[ch2]) is false:
    Decrement ch2. 
    Return if ch2 < 0.  
    -- pass back true or false, you get to figure out which

// At this point you are looking at 2 alphabetic characters. …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree. Are they really teaching LET for VB? Or is this another version of BASIC? Maybe best in Legacy and Other Languages

DO WHILE count < flipq
    LET num=INT(RND(0)*2)+1
    IF num = 1 THEN
        PRINT "T"
        'LET count = count + 1      ' put this before the IF
        'LET tcount = tcount + 1    ' uncomment this and duplicate it for heads
        'LET maxtcount = tcount
        'IF maxtcount > tcount THEN
        'LET maxtcount = maxtcount
        'END IF
      ELSE
          PRINT "H"
      END IF
LOOP

Initialize tcount and hcount before the while loop.

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

ok thx where do i go to get started?

By contacting them. They will tell you what you need to do to access your space.

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

Why not use a third party library to access the database using C++ and build the GUI using GTK+ or wxWidgets ?

No point in learning a new lang, and that too VB !!! It would be better if you invest your time in Python or something like that.

Why learn a 3rd party package when you know VB? I'd have to learn GTK+, wxWidgets, or Python. I already know VB. Hence my choice. ;)

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

Also C/C++ is not very good for reports -- COBOL (how do you spell Yuk!) is better for that.

Heck, C is better than C++ for reports...


I disagree with the dissing of VB. Yes it's fairly simple to learn. Yes it's not as powerful as C++. But it does an excellent job (mostly) of easily building GUI systems. There is a definite place in the programming hierarchy for tools that can accomplish the job easily and can create a robust, usable, and stable system. No, I wouldn't use it for real-time programming. But as a front-end to one it's much simpler to deal with than MFC. For data aquisition and database manipulation, it's much easier than C/C++.

Easier is good, as long as you aren't sacrificing something that is necessary. Need speed, C++. Just need a GUI to access a DB, VB would be my choice.

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

Since you only have one DATA defined, simply remove all data. from your code and add the definitions contained in DATA without the structure.

IOW, where you have struct DATA data; use

pid_t pid;
   int lenth;
   char buff[128];

instead and remove the structure.

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

Thanks I got it to work, but I'm not reading in the data from the file correctly. It looks like:

5   20
5   30
5   40

So I should be reading in only 3 lines for 3 calculations. The 5 is the temp, and the next nmber is the wind speed. Instead, it reads 6 numbers and makes 6 calculations :/

Well, we don't know what your code looks like that reads the file (I assume you've changed your code), there's not much we can suggest. Maybe you can post that section.

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

A buddy of mine turned me on to Tom's CD. He's got one where the caller is trying to sell him a cemetary plot, and Tom takes the call as a sign he should commit suicide. It's a real scream! Tom decides to buy a plot and want's it on credit. The telemarketer says maybe he should pay cash, considering...

I think this one posted here is almost as good.

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

The way I generally work on forums is this:
I will open each thread from one forum in different tabs. While looking at one of the threads if a link looks interesting, I will click the link to get the new window open (or in another tab). I'm generally not ready to look at that page yet, but don't want to lose it or search for it later. Finish the thread, then check that link.
On to the next thread.

In non forums I tend to do a similar thing, just mostly in new tabs instead of windows.

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

It seems to me that your program is defined above -- each function and it's algorithm -- in your first post. You can almost convert those steps directly into code.

The only thing that's missing is your main() which processes your initial loop from 4 to 1000.

Although I'd change one aspect of your first function listed:

{ 
    for ( int m = 2; m*m <= n; m++)
    {
        if(n % m == 0)
        {
             return 0;  // this is your TRUE condition
        }
    }
    return 1;  // this is your FALSE condition
}

In C/C++, 0 is generally regarded as FALSE, 1 is TRUE.

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

You can't program an exuation using math format. You have to use computer format. a(2+x) must be written as a[B]*[/B](2+x) . You must explicitly tell the program to multiply with *.

And be sure to put parentheses around every two terms. Don't assume a + b * 3 is the same as (a + b) * 3 -- it isn't.

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

As Ancient Dragon implied, with 400+ lines of code, could you just post the section(s) you're having trouble with?

1. I don't know why when I enter the number in, when it prints out the number, it becomes smilies or some kind of maths code. Please tell me what I have done wrongly and how should I correct it.

Dozens of printfs, can't tell where.

There is one thing I did notice, though. You're using strncpy() and strncmp():

strncpy(filename1, u, 3);
    strncat(filename1, ".txt", 4);

Run this program and see why you should switch to strcpy() and strcmp():

#include <stdio.h>
#include <string.h>

int main()
{
    char *t1 = "123456789\0ABCDEFGH";
    char *t2 = "zxcvbn";
    char *t3 = "asdfg";
    
    printf("%s\n", t1);
    strncpy(t1,t2,3);
    strncat(t1,t3,3);
    printf("%s\n", t1);
    
    return (0);
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I know I'm supposed to have a starting value for total but I don't really understand what it is or where I should put it, I'm sorry if I sound really stupid but I'm very new to this so most stuff takes me awhile to figure it out. So where and what is total then?

If you are going to add numbers to a running total, what value should the total start with before you start adding? -10? 20? 0? Pick one. Key point, before you start adding...

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

Excellent!!!

If I may humbly suggest a few visual suggestions, though:

comments in green
"Strings" and 'characters' in blue
Numbers in dark blue
Keywords in bold purple (no underline)
All else is black
C/C++ functions don't need to be colored, but if they are, use a dark color like maybe dark red

All the colors should be of a similar intensity. The switch from the keyword-yellow to function-underline/blue is too striking.

I also notice in the [code=c] section, there is no formatting displayed in the edit window. I assume that's just a glitch, but I thought I'd at least point it out, just in case.

Also, is there a possibility to close up the gap between lines just a tad -- at least as a test? I'd like to see a little less space and a little more code. Instead of 1.5 spacing maybe 1.25.

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

Use sprintf (or snprintf (if available this is the best )) to create a string in the form of "InputNumber%d", and pass that to the AnimationNodeInCreate function.

int i;
char label[ 15] = "";
for (i=0;i<36;i++)
{
         sprintf ( label, "InputNum %d", i );
         mInputs[i] = AnimationNodeInCreate ( i, label , ANIMATIONNODE_TYPE_NUMBER );
}

The format I would use is

sprintf ( label, "InputNum%04d", i );

This will tack on the number without spaces, and the number will be 4 digits, zero filled -- InputNum0023 -- but that's just me... :mrgreen:

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

Dave's link no longer works, but this one does...

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

I'm glad you're finding it more useful than it's predecessor.

Yeah, it's kool! But shouldn't it open in a new window -- like [search]links[/search]? (I had to try it out)

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

I am totally stuck on this problem and would love it if anyone knew how to help me fix it! Thanks for any input!!!

When asking for help, you really need to tell us what your problem is. We can't always guess.

Here are directions:
Write a program that asks the user for a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loops will find the sum of 1,2,3,4,....50.
Input Validation: Do not accept a negative starting number.

So in your code:

for (number = 1; number <= maxnumber; number++)
    {
    total += number;
    // What is the starting value of total?  It isn't 0. You never initialized it.
}

    cout << "The sum of all integer numbers from 1 to ";
    cout <<  << " is: " << total << endl;
//          ^   what goes here?
    
      if (number >= number);
// This IF does nothing...
      
    system("PAUSE");
// Don't call SYSTEM, use [I]cin[/I] or [I]cin.get()
[/I]
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I tried this but am confused and received errors.

What errors? We can't help if we don't know what the errors are nor what the new program looks like.

Remember, to output *s on the next line you have to output a '\n' at the end of the line you're on.