Narue 5,707 Bad Cop Team Colleague

>void main()
int main()

>if((StringPtr = new char[26]) == NULL)
This may or may not correctly handle errors depending on how old your compiler is.

>*(StringPtr+i) = String;
You know, you can do StringPtr[i] = String[i]; too. It's a lot easier to read and write.

>cout << "StringPtr = " << StringPtr << endl;
You forgot the last character, the '\0'.

>delete [] String;
And why are you trying to delete an array?

>For "delete [] String;" part, I tried to use the for loop to see if it works.
Why don't you take that entire line away and see if it works? You're not supposed to release memory unless you explicitly allocate it.

Narue 5,707 Bad Cop Team Colleague

>Why destructor with ~ is used in cplus-plus coding for every constructor?
~ is the complement operator in C++, and a destructor is the complement of a constructor. The creator of the language admits that this may have been "overly clever", and I agree thoroughly, but at this point there's nothing we can do about it.

For questions like that about the how and why of C++'s design, there's a book by the creator called "The Design and Evolution of C++".

Narue 5,707 Bad Cop Team Colleague

>Hm...we have got a unique kind of girl programmer here...
You knew that already though. ;)

Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

>I figured psuedocode would accomplish what I'm seeking.
You didn't specify if this is to be in C or C++. In C, look for the strchr function. In C++, look for the find_first_of member function of the string type.

Narue 5,707 Bad Cop Team Colleague

>I would really like to see more ladies in this business! I am male!
I'm sure that's a completely selfless desire. ;)

It's amusing to watch how women are treated in the field. In my case, it's always assumed that I'm lacking in knowledge or experience. This is odd to me because the jobs I apply for are senior and very difficult. The guys try to mentor me before realizing that I'm pretty far beyond them in ability. I'm left alone while they recover their egos. Finally, I end up becoming "one of the guys" when they get over it and see me as a skilled programmer rather than just a female programmer.

Narue 5,707 Bad Cop Team Colleague

>I have newer edition of narue keybord, its Logitech G15
I looked at that, but none of my research showed the LCD to be useful beyond a small range of games. Hardly worth an extra $30USD. Do you actually make use of it? That's the only difference between the two keyboards. ;)

Narue 5,707 Bad Cop Team Colleague

I imagine that those are member functions and their definitions need to be prefixed with playerType:: .

Narue 5,707 Bad Cop Team Colleague

>but iam totally fail
Yes, yes you are.

Narue 5,707 Bad Cop Team Colleague

>If that were the case then there would be no need for private detectives.
Then hire one. They'll certainly know the law better than you and can avoid the mess you're sure to get into if you follow your present train of actions.

>By no means have I asked to obtain this information illegaly. Just wanted
>to see if others had a creative way to do such.
Walk in and ask for it. If they refuse, ask them why. Most likely it's not publicly available information and anything creative is highly likely to be illegal. It's just that simple.

Narue 5,707 Bad Cop Team Colleague

>I have some information regarding some illegal practices conducted by the
>company. However without proof I cannot go to the police. I need a past
>employee to corroborate my story.
Been watching too much television, have we? If that's really your reason, and you actually manage to pull it of, don't you realize that the most likely one to be prosecuted is you? Spare me the cloak and dagger crap. If you have information, give it to the police and let them do the grunt work of confirming it. That's their job, and you're less likely to go to jail for illegal acquisition of private data.

Narue 5,707 Bad Cop Team Colleague

If you don't have a legitimate way of getting that information, I can't think of any legal reason why you would need it.

Narue 5,707 Bad Cop Team Colleague

Iya, that's what I'm here for. :)

Narue 5,707 Bad Cop Team Colleague

>Your views ?
Let's add five years to the program. You've moved on to more interesting things and there's a change order. How is the maintenance programmer supposed to know that negative numbers are taboo? What if the change order requires them? By over-intellectualizing, you've introduced a bug and a fix that wouldn't be necessary if your code was written defensively from the start.

Narue 5,707 Bad Cop Team Colleague

You realize that this thread has been inactive for several years, yes? :rolleyes:

Narue 5,707 Bad Cop Team Colleague
void print_n ( const char *s, int n )
{
  while ( --n >= 0 )
    printf ( "%s", s );
}

void jump ( int n )
{
  /* We can only jump 9 inches */
  if ( n < 9 ) {
    print_n ( "* ", n );
    putchar ( '\n' );

    jump ( n + 1 );

    print_n ( "* ", n );
    putchar ( '\n' );
  }
  else {
    print_n ( "* ", n );
    putchar ( '\n' );
  }
}

It works okay for me. The only part that's missing is the extra step of printing leading whitespace, and you can easily do that by adding a second argument to jump that counts down instead of up.

Narue 5,707 Bad Cop Team Colleague

>He he, does that mean my code is safer?
Yes. In these two comparison functions, the first is far safer:

int compare_exact ( const void *a, const void *b )
{
  const int *ia = a;
  const int *ib = b;

  if ( *ia < *ib )
    return -1;
  else if ( *ia > *ib )
    return +1;
  else
    return 0;
}

int compare_arithmetic ( const void *a, const void *b )
{
  const int *ia = a;
  const int *ib = b;

  return *ia - *ib;
}

The latter works great if the subtraction doesn't cause signed overflow, but when it does (and it will; probably at a client demo or press release) it'll cause undefined behavior.

>How long are you on maternity leave for?
Until the first of April, then I start officially telecommuting. But on my team it's implied that I'm out of commission indefinitely except for high priority issues that need the Narue touch. ;)

Narue 5,707 Bad Cop Team Colleague

Go to the last node of the first list and attach the first node of the second list to it:

last->next = list2;

If you have a doubly linked list, make sure the back pointer is updated:

last->next = list2;
list2->prev = last;
Narue 5,707 Bad Cop Team Colleague

>Bruce Eckel's books are WAY overrated.
I disagree. Thinking in C++ volume 2 is a good book. The code is tolerably ugly, but the content is sound and useful. I actually haven't read volume 1 though, so you could be right on that one.

Narue 5,707 Bad Cop Team Colleague

>What I meant with the things not being allowed is that the output wanted was to be straightforward.
The output has no relationship to how you produce the answer. You can solve the problem a dozen wildly different ways and get exactly the same desired output that you posted.

>Only the sign matters here (+ve, -ve, zero).
>return (sp1->wordOccurrence - sp2->wordOccurrence) ;
Sure, only the sign matters, but it's also the sign that kills you with this code. You're a smart guy, so I'll give you three words of advice on why this is a poor solution: signed integer overflow.

~s.o.s~ commented: *shoots himself in the head* I overlooked that possibility, thanks - ~s.o.s~ +14
Narue 5,707 Bad Cop Team Colleague

>I attempted to use your example code but that didn't seem to work for me.
Not helpful. If it doesn't work, explain how it doesn't work. Did it simply not compile and run for you? Did it fail when you tried to make it print a diamond? What changes did you make? What result did you get? "It doesn't work" is the kind of useless reply that makes me want to smack people.

Narue 5,707 Bad Cop Team Colleague

>syscall( 10, argv );
This says to send the interrupt 10 (which references the unlink operation) to the system for processing. It's directly equivalent to saying unlink ( argv[i] ); , which would be a much better solution:

#include <unistd.h> // read/write

int main( int argc, char *argv[] )
{
  int i;

  for ( i = 1; i < argc; i++ )
    unlink ( argv[i] );

  return 0;
}

>Does this involve using the tail command?!
tail doesn't have a matching C interface. Try saying man popen if you want to use it.

Narue 5,707 Bad Cop Team Colleague

>I don't understand how that works.
Did you only read the code? I described it in detail and even took the time to come up with a description in clever layman's terms too.

>why does going down keep getting called? there is no recursive call there
That's because you're already in the recursion. It goes like this:

1
   2
      3
         4
            5
               6
                  7
                     8
                        9

You're already nine calls into the recursion. It doesn't just magically end, you have to go back out again:

1
   2
      3
         4
            5
               6
                  7
                     8
                        9
                     8
                  7
               6
            5
         4
      3
   2
1

Remember, a function has an entry and an exit, but recursion is just a long string of nested function calls.

Narue 5,707 Bad Cop Team Colleague

>thanks for the things about frequency tables but we arent allowed to use them.
What are you allowed to use if you can't cache the words and counts? I can think of one way (that could be considered a beginner solution) off the top of my head, and the logic is extremely painful even for experienced programmers.

Narue 5,707 Bad Cop Team Colleague

>For the bottom half should I create another recursive function to print the
>bottom half of the diamond and call it indirectly by the topDiamond function?
You don't need to. Let's play a game. Get up from your computer and go to a nice empty spot in the room and start jumping up and down. I'll wait...


Did you have fun? :) Well, that jumping motion is how the entire process of recursion should look in your mind.

You start the recursion by jumping up. When you get as high as you can go, you reverse direction and come back down. Now, let's say you can jump really slowly and you want to count how many inches high you are. You jump up and say 1, 2, 3, 4, 5, 6, 7, 8, 9 and can't go any higher. So you start coming down and say 8, 7, 6, 5, 4, 3, 2, 1.

When you were counting up, that's the entry path of the recursive process. You're digging deeper and deeper into the recursion. When you couldn't get any higher, that's the base case for the recursion, the stopping case. But you're already deep into the recursive calls, so you still have to backtrack and come back out. That's the exit path of the recursive process, and you don't have to just let it happen silently. You can do actual work during the exit path (after the recursive call returns):

#include …
Narue 5,707 Bad Cop Team Colleague

>this works as infinite unconditional loop is'nt it?
Yes.

>y won't u get the error the redefinition of var x?
Why would you? The variable is only defined once at any given time. It's exactly the same as if you did this:

while ( 1 ) {
  int x = 9;
}

Well, not exactly the same, but the example still stands. ;) Now, in practical terms, the variable isn't likely to actually be inside the loop such that every iteration causes the storage to be reallocated. It's just only visible within the loop body and reinitialized with every iteration.

Narue 5,707 Bad Cop Team Colleague

Occurrences can be done with what's called a frequency table. It's a really cool thing, and it's really easy to implement. But, I'm not going to write your program for you, so I'll give you a frequency table that counts the occurrences of single characters and let you figure out how to do it with words using the excellent links you've already been given (otherwise I would hurt Dave's feelings):

#include <stdio.h>
#include <limits.h>
#include <ctype.h>

int main ( void )
{
  int freq[CHAR_MAX + 1] = {0};
  int i;
  char input;

  while ( ( input = getchar() ) != EOF )
    ++freq[input];

  for ( i = 0; i < CHAR_MAX + 1; i++ ) {
    if ( freq[i] != 0 ) {
      if ( isalpha ( i ) )
        printf ( "%c:\t%d\n", i, freq[i] );
      else
        printf ( "%#X:\t%d\n", i, freq[i] );
    }
  }

  getchar();

  return 0;
}

I talk about frequency tables a lot because they're so useful, you might even be able to find an exact solution to your problem by searching the forum. ;)

Narue 5,707 Bad Cop Team Colleague

>maybe just maybe one of the experts out there could help me out.
No, sorry. We can make educated guesses (as I've already done), but you're simply not providing enough information. Go back to whoever gave you that code and tell them that you can't fill in a missing statement when you don't even remotely know how the statement is supposed to fit into the rest of the code. Here, this is a perfectly valid and correct answer to your question:

p = new NodeType;
p -> data = 18;
q = new NodeType;
q -> data = 32;

cout<<"Narue is kewl!\n";

q-> link = NULL;

Don't you see how absurd your request is?

Narue 5,707 Bad Cop Team Colleague

Anything by W. Richard Stevens is good.

Narue 5,707 Bad Cop Team Colleague

>If I knew then I wouldn't be asking for your help, now would I ?
There's a significant difference between knowing the problem and knowing the cause of the problem. Not the least of which being that I'm talking about the former and you're talking about the latter. Do you go to a doctor and just tell him to heal you? Do you go to a mechanic and tell him to fix any problems he finds? No, you go to a doctor when you're injured or ill, and can tell him where it hurts. You go to a mechanic when your car makes a funny noise that you can describe to the mechanic.

I'm the doctor, tell me where it hurts. I'm the mechanic, describe the noise you're hearing. Then I'll use my expertise to help you correct the problem. Now, what part of that are you having trouble understanding?

Narue 5,707 Bad Cop Team Colleague

>I fix the link part any responses
Um, good for you? You still haven't specified enough of a problem to be solvable. You tell us what the code is supposed to be doing, and we'll tell you why it isn't working. Until then, get used to not having any useful responses.

Narue 5,707 Bad Cop Team Colleague

>GameBoard that GUI class that we can't change, am I right?
No. You're the data layer, you don't (and shouldn't) know jack about the presentation layer. That's as simple as I can put it. The GameBoard class is an intermediary between the data layer and the presentation layer. It could be as simple as an 8x8 table of integers where each integer represents a different game piece. You set the values and the presentation layer uses those values to draw stuff. The data layer should be completely modular in that you can cut it out, plug it in to a completely different presentation layer, and everything will work as long as the presentation layer uses GameBoard and GameMove according to your interface.

The only thing that can't change is the public interface of your classes. That is, whatever the public interface of GameBoard and GameMove is, and the two member functions that Game defines. Everything else can change because doing so won't screw up what the GUI people are working with.

Narue 5,707 Bad Cop Team Colleague

You can tell a lot about a person from their keyboard and mouse choices. What's your favorite keyboard and mouse? Why do you like it? What kind of work do you do?

My favorite mouse is the Logitech G5. Aside from having a comfortable grip and gaming quality stats, I love being able to change the sensitivity and weight. My old mouse was a Microsoft wireless dealie, and I stuck with it for the longest time because it felt so good. The G5 is much better though. :)

My favorite keyboard is this little beauty. The Logitech G11 gaming keyboard. It's designed for gamers, but as a programmer, I fell in love with it immediately. I prefer to work in the dark (especially at work where fluorescent lighting gives me a headache) and the blue lighting is great. :) I like the music controls, but that's pretty standard on higher end keyboards anyway. The best part is the macro keys. I've come to rely on them for everything from loading applications to handling common code operations. Of course, I also find typing to be incredibly comfortable with this keyboard. That's a first for me; I used to just suffer with the awkwardness of whatever keyboard I was using.

Narue 5,707 Bad Cop Team Colleague

>sorry but that all the info that i have
No wonder you can't figure it out, you don't even know what the problem is!

>Your struct doesn't contain a member called link ?
Yea, I saw that too...no, really. :o ;)

Narue 5,707 Bad Cop Team Colleague

>Here is the ?
>Next ? is
? is a sentence modifier. It has no meaning by itself in literature. Please spell out the word "question" for those of us that abhor useless abbreviations and shortcuts. Thanks.

>My friend said that should be the parameter, but think that its the argument
The whole thing is called a template declaration. The formal grammar for it is:

[I]template-declaration[/I]:
        export[I](opt)[/I] template < [I]template-parameter-list[/I] > [I]declaration[/I]

Where the declaration at the end is a class or function definition. The parts before the declaration aren't treated as a single unit, and thus don't have a unifying name.

>I said it was the parameter, and my friend said that it was the argument.
The C++ standard calls it a parameter, so you're correct.

Narue 5,707 Bad Cop Team Colleague

>Yeah, I understand it's old
I hear that a lot, but people still try to use graphics.h on Windows XP. Clearly the flow of information is getting interrupted somewhere along the line. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

You forgot to provide an interface for "get initial state". I also think that you're thinking in the wrong direction with "move". You provide the data, and the GUI uses that data to draw a representation of it. Something like this:

class GameBoard; // Not really important to the question
class GameMove; // Also not important

class Game {
public:
  virtual const GameBoard& GetInitialState() = 0;
  virtual const GameBoard& SetMove ( const GameMove& move ) = 0;
};

All communication is done through the Board and GameMove objects. You provide the GUI with the state of the board and the GUI provides you with move information that's dealt with polymorphically. Your class doesn't know or care how the GUI uses that information, just as the GUI doesn't know or care how you use the move information.

Narue 5,707 Bad Cop Team Colleague

p->link = q; , perhaps? It's hard to say with your little uninformative guessing game.

Narue 5,707 Bad Cop Team Colleague

>but im newbie
I don't care. You ask questions, I answer them. If I need to know your level of experience, I'll ask a pointed question to determine that. Calling yourself a newbie serves no purpose at all.

>how could i use the code you have in my code???
I was thinking that you define the array and just paste the code I gave you into main as well:

#include <stdio.h>

#define ROWS 3

int coordenada ( const char *s, const char *t )
{
  const char *p;

  for ( p = s; *p != '\0'; p++ ) {
    const char *x = p, *y = t;

    for ( ; *x != '\0' && *y != '\0' && *x == *y; x++, y++ )
      ;

    if(*y == '\0')
      return p - s + 1;
  }

  return -1;
}

int main ( void )
{
  const char *array2d[] = {
    "blablablablablabalblablabalbla",
    "imtriyingtodomybestbutishard",
    "blablahardlablbalablabalabalbl"
  };
  const char *target = "hard";
  int i;

  for ( i = 0; i < ROWS; i++ ) {
    int col =  coordenada ( array2d[i], target );

    if ( col != -1 )
      printf ( "\"%s\" found at (%d,%d)\n", target, i, col );
  }

  return 0;
}

It's not exactly brain surgery if you have a book on C.

Narue 5,707 Bad Cop Team Colleague

>Anyone know if the 2006 version of Turbo
>C++ comes with that graphics library?
No, Turbo C++ 2006 is a modern development tool. graphics.h is an ancient library that only works on ancient systems. If you want to do graphics, stick to Win32 or .NET. IF you don't like the "evil empire", use Allegro or SDL, or any of the other freely available libraries that actually work on current systems.

Narue 5,707 Bad Cop Team Colleague

You're not even using a two dimensional array. But if you were, did it occur to you that you can do this?

for ( i = 0; i < ROWS; i++ ) {
  int col =  coordenada ( array2d[i], target );

  if ( col != -1 )
    printf ( "\"%s\" found at (%d,%d)\n", target, i, col );
}
Narue 5,707 Bad Cop Team Colleague

>Can you explain me the answer or show it in C++ code?
:-| What was your answer?

Narue 5,707 Bad Cop Team Colleague

>Maybe it hasnt occurred to you that ive only been learning C for 5-6 days
>give or take, in between lectures and other deadlines
Unless you're embarrassed that Salem made some astute and accurate observations, I don't see what this has to do with anything. Lack of experience doesn't exempt you from learning good programming practices.

>b) useless unless you apply the rule consistently in your code.
That would be fine, if it were possible to apply the rule consistently and get consistently good results. ;)

Narue 5,707 Bad Cop Team Colleague

>Correct the problems one error message at a time.
Starting from the top, by the way. Syntax errors higher up in the code tend to cause many errors later in the code. If you don't start at the top, you'll end up chasing phantom bugs.

Narue 5,707 Bad Cop Team Colleague
Narue 5,707 Bad Cop Team Colleague

>what do you think guys?
Your formatting is horried, void main is incorrect, gets is an extremely bad habit, and the algorithm is broken.

Let's start with the formatting. Braces are there for a reason. They tell you when a block starts and when a block ends. However, if you chain the closing braces all on the same line, it doesn't help people who are reading the code[1]. Here's a better format:

int underStringPos(char *source,char *under)
{
  char *sourceptr = source;
  int counter=0;
  while (*sourceptr){
    if (*sourceptr == *under){
      char *s = sourceptr, *u = under;
      while (*u){
        s++,u++;
        if (*s != *u)
          break;
        return counter;
      }
    }
    sourceptr++;
    counter++;
  }
}

Now it's obvious what's nested where and you can more easily follow the flow of execution.

I'll let void main and gets slide, but main returns int, and fgets is much safer than gets.

Now for the logic. Run your program with "testing" and "stupid algorithms are hard to get right". It returns 2 because your loop breaks early. If the first two characters of the substring are matched, the rest of the substring is completely ignored even if it doesn't exist in the source string (exercise: explain why). Perhaps if you return the index when *u is '\0'. That ensures that the loop has run to completion and the entire substring has been matched.


[1] This is a consistent rule of formatting. If you put multiple independent things on …

Narue 5,707 Bad Cop Team Colleague

You're making a series of nested boxes. The reason you failed is because you're trying to do it all at once, probably with no prior experience solving this kind of problem. So what you need to do is simplify it down to something that you can solve. For example, create a single filled box:

N: 4

1111111
1111111
1111111
1111111
1111111
1111111
1111111

Now draw it empty:

N: 4

1111111
1     1
1     1
1     1
1     1
1     1
1111111

The key element is that N designates a cross down the center of the box:

111*111
111*111
111*111
*******
111*111
111*111
111*111

You count up to N and then back down to 0. Once you understand and can implement all of this, try looking for patterns between the first row/column and the central row/column. That's where you come up with the final parts of the algorithm.

And no, I'm not going to tell you how to do it. It's important that you work through the process on your own. However, I can and will offer hints after you make some kind of attempt and show us your results.

Narue 5,707 Bad Cop Team Colleague

Perhaps you should ask your question with a new thread in the VB forum instead of resurrecting a four year old C++ thread. kthnxbye.

Narue 5,707 Bad Cop Team Colleague

>Hey if they were instructions any where i would follow them to the final dot.
Sorry, but I'm calling you on that. Either you're lying, or you selectively ignore instructions so that you can whine when people correct you. The instructions are watermarked in the text editor. They're pretty hard to miss, as you see them every time you post.

Narue 5,707 Bad Cop Team Colleague

>access c++ private data members without using the " Friend" type
Why is this such a common question? It's insanely stupid.