Narue 5,707 Bad Cop Team Colleague

What have you done so far to solve this problem?

Narue 5,707 Bad Cop Team Colleague

Hmm, close.

>void (*ptr)();
Pointers to member functions have different syntax than pointers to functions. You need to specify the class:

void (A::*ptr)();

>ptr = &a.show;
Member functions aren't stored internally in objects. You need a class resolution for this:

ptr = &A::show;

>*ptr();
Non-static member functions require an object to run. Likewise, pointers to non-static member functions also require an object to act upon. There's a special syntax for that too:

(a.*ptr)();

Here's the whole thing:

#include <iostream>

class A{
public:
  void show() {
    std::cout << "Hello World";
  }
} a;

int main()
{
  void (A::*ptr)();
  ptr = &A::show;

  (a.*ptr)();

  return 0;
}

If show were a static member function, your code would work just fine after changing *ptr(); to (*ptr)(); or even ptr(); , as you don't have to dereference a function pointer to call the function.

Narue 5,707 Bad Cop Team Colleague

>I DONT know how to do that...
I'm willing to bet you do, but you're just not making the connection:

#include <fstream>
#include <string>

// Open a file and display it
void showFile ( const char *filename )
{
  std::ifstream in ( filename );
  std::string line;

  while ( std::getline ( in, line ) )
    std::cout<< line <<'\n';
}

Though I'll go out on a limb and wager that you don't want console output, but rather you want to start some random text editor that will display the file for you. That's non-portable, but you might do something like this:

#include <cstdlib>
#include <string>

// Open a file and display it in the specified program
void showFile ( const std::string& program, const std::string& filename )
{
  std::system ( ( program + " " + filename ).c_str() );
}
Narue 5,707 Bad Cop Team Colleague

>is there any showFile() type of function in libraries??
No, you have to write it yourself.

Narue 5,707 Bad Cop Team Colleague

A more detailed answer is that C doesn't really have a string type. Because there's no string type, we use arrays of char with a special character acting as the end of the string, and all of the rules for arrays apply. In other words, arrays aren't a first class type that can be assigned, so to copy one array to another, you have to use a loop:

size_t n = strlen ( src );
size_t i;

for ( i = 0; i < n; i++ )
  dst[i] = src[i];

dst[i] = '\0';

The strcpy function does that for you, more or less.

Narue 5,707 Bad Cop Team Colleague

>Would a text file be the most professional way to save the settings for an executable?
Why wouldn't it be? If you don't need anything more sophisticated it would be unprofessional to push more of a solution than you require.

>So, what kind of file is IE7 or most mainstream programs using to store user defined settings?
If I were to guess, I'd guess that it's adding and updating keys in the registry. That's not a recommended practice.

Narue 5,707 Bad Cop Team Colleague

You might find this enlightening, but it's pretty in depth.

Jishnu commented: Excellent article :) +2
Narue 5,707 Bad Cop Team Colleague

>What does Zw stand for?
It's a mystery. The common assumption is that Zw was chosen because it meant absolutely nothing and there was little chance of something popping up that would make it significant.

>I'm not able to understand this thing in the italics.
Put simply, the Zw* versions will do some magic kernel stuff when called in kernel mode, and the Nt* versions won't. In user mode, both evaluate to the same thing.

Narue 5,707 Bad Cop Team Colleague

>the output is in seconds,right??
That's what I said:

You can divide the result by CLOCKS_PER_SEC and get the result in seconds

Narue 5,707 Bad Cop Team Colleague

>what's the solution??
Spell it correctly. It's CLOCKS_PER_SEC, not CLOCK_PER_SEC, and it's defined in ctime.

Narue 5,707 Bad Cop Team Colleague

>what's its unit...seconds..milliseconds..microseconds..
>or depends on clock frequency...???
From a standard library perspective, you don't know. Everything after this point assumes non-portable things about your implementation.

You can divide the result by CLOCKS_PER_SEC and get the result in seconds, but be sure to cast one of those operands to a floating-point type or you'll likely get a lot of zeros unless your program takes more than a second.

Narue 5,707 Bad Cop Team Colleague

>I missed this line when skimming through the Keep it Spam Free rules
I constantly find myself reviewing the rules. It's a good practice if you ever feel the need to cite them in a discussion. ;)

Narue 5,707 Bad Cop Team Colleague

>You were spamming the forum through your signature
>and avatar and that violates keep it spam free.
Signatures are the correct place for self-promotion or solicitation, provided it's within reason. ithelp's signature is indeed within reason, though that particular discussion may have taken place before jwenting was promoted to moderator.

>Then you tried to get other people to spam the forums
>by doing what you have done with your signature.
I disagree. While you can interpret that implication from his thread, an equally valid interpretation is that he was simply asking a question and starting discussion. You can't assume what ithelp's intentions were.

>I think that clearly violates keep it spam free.
I don't think that either violate Keep It Spam-Free, and I've reversed the infraction.

>Just because I replied to a post where jwenting called me subhuman,
>now he is taking revenge by giving unnecessary infraction.
That's an unwarranted assumption. Moderators are strongly encouraged to keep their personal feelings out of decisions when enforcing the rules.

Narue 5,707 Bad Cop Team Colleague

>I'm still gettin fopens deprecated though...is that anything to worry about?
Didn't I say it's harmless but annoying, and that you can ignore it? Those particular deprecation warnings are just Microsoft being stupid. They want you to use their non-standard "safe" libraries instead of the portable standard libraries.

Narue 5,707 Bad Cop Team Colleague

>fopen still comes back deprecated.
Ignore the warning then, it's harmless (as long as you consider annoying as hell harmless).

>And if I define "line" as "char * line", it compiles but I get an error when I try to run it then.
Most people don't jump over arrays and go on to pointers. You know how to make an array right?

char line[1024];
Narue 5,707 Bad Cop Team Colleague

>do you also think that something should be done about
>those who give out neg rep which was uneccesary?
What do you suggest? Rep is subjective by nature, so how do you determine what is "unnecessary"? Not to mention that rep is intended as a fun little aside and not a realistic measure of a member's reputation in the community. Don't take it too seriously.

Narue 5,707 Bad Cop Team Colleague

>Lol I'm looking to put some code such as that in my main.
So what's the problem?

>Is the code you gave me suppose to be the defintion for <snip strstr declaration>
No, it's the code that uses strstr to search a file. That's what you said you wanted, right?

Narue 5,707 Bad Cop Team Colleague

>>pride
i think that makes no sense. sure some make enough money in their day job to not not need this but it still is usefull. and those whom are the best would have more signatures and earn more money so the more money you earn from signatures might be a reflection of how valuable a member you are.

It's not about money, it's about selling away your credibility. I'm probably an expert in my field, but I'm not about to use my name to sell products and services unless they're directly related to the forums I post in and I feel strongly enough about them to recommend them anyway. Putting links in my signature to the highest bidder reeks of a materialistic greed that a lot of geeks find repulsive.

uniquestar commented: Well Said Sir +3
~s.o.s~ commented: Except that it's not *sir*... +20
madoverclocker commented: well said +1
Narue 5,707 Bad Cop Team Colleague

>I want this to return NULL if the needle string is not found
>in the haystack string and otherwise return the pointer to
>where the needle is returned.
You're in luck, that's precisely how strstr works.

>I was hoping someone could help me find a way to implement it as I want.

int line_number = 0;

while ( fgets ( line, sizeof line, in ) != NULL ) {
  ++line_number;

  if ( strstr ( line, "is" ) != NULL ) {
    printf ( "%d: %s", line_number, line );
    fflush ( stdout );
  }
}
Narue 5,707 Bad Cop Team Colleague

>What are the reasons that geeks do not feel like renting signature links ?
Probably because geeks tend to have more pride than that.

Narue 5,707 Bad Cop Team Colleague

>Both these members have said contradictory things.
No, they said the same thing in a different way. back() returns a reference to the value of the last item in the collection. end() returns an iterator to one past the last item in the collection.

Narue 5,707 Bad Cop Team Colleague

It looks like the location and the robots are disconnected, so the first algorithm that comes to mind is a simple one:

for each robot from robots
  integer r := robot.row()
  integer c := robot.col()

  select grid[r][c] from
    case 'R': grid[r][c] := '2'
    case '2': grid[r][c] := '3'
    case '3': grid[r][c] := '4'
    case '4': grid[r][c] := '5'
    case '5': grid[r][c] := '6'
    case '6': grid[r][c] := '7'
    case '7': grid[r][c] := '8'
    case '8': grid[r][c] := '9'
    case '9': # do nothing
    default: grid[r][c] = 'R'
  end select
loop

That should give you a start.

Narue 5,707 Bad Cop Team Colleague

>But why they put a option with struct when they have a class?
Why not? How do you know a class was even an option?

Narue 5,707 Bad Cop Team Colleague

>bool validUserInput (true);
This guy should be reset inside the loop. Right now if you fail once, it fails forever.

>if ( rate % 2 != 0 ) validUserInput = false ;
When rate % 2 is 0, the number is even. This test will set validUserInput to false when the number is odd, which isn't what you want.

>while (validUserInput);
Perhaps you meant while ( !validUserInput ) .

Compare and contrast:

bool validUserInput;

do {
  validUserInput = true;

  cout << "Please enter an odd value between 3 and 31: " << endl;
  cin >> rate;

  myWaveForm.getSampleValue( rate );

  if ( rate % 2 == 0 ) validUserInput = false ;
  if ( rate < 3 ) validUserInput = false;
  if ( rate > 31 ) validUserInput = false;
}
while (!validUserInput);
johnnyjohn20 commented: explained my problem thorougly +1
Narue 5,707 Bad Cop Team Colleague
iamthwee commented: Use of slang is prohibited at Daniweb! :) -2
Narue 5,707 Bad Cop Team Colleague

>Am I not passing the right thing to the function or making another mistake somewhere else?
Both, actually. I'll give you a few hints:

1) A pointer is a variable that holds an address.
2) All parameters in C are passed by value (they're copied).

Did you figure it out? If you copy a pointer, then allocate memory to the copy, you've done jack squat to the original pointer. There are two good solutions:

1) Pass a pointer to the pointer to your function. Then allocate memory to the dereferenced pointer.
2) Return the newly allocated pointer and assign it to the original.

Narue 5,707 Bad Cop Team Colleague

>the pointer to the next
Should probably be NULL unless you already have the next node available to link.

>the head pointer of type "node"
Which you already have because you're trying to assign it.

>and a label of type char
Which isn't exactly a label. If it's an array you can leave it, but if it's a pointer to char, you should probably allocate some memory to it before copying a string in there.

>what should I allocate memory too?
My guess would be something like this:

listHolder *listHolderPtr = malloc ( sizeof *listHolderPtr );

if ( listHolderPtr != NULL ) {
  listHolderPtr->label = malloc ( <a suitable size> );

  if ( listHolderPtr->label != NULL ) {
    strcpy ( listHolderPtr->label, "Hello world" );
    ...
  }
}
Narue 5,707 Bad Cop Team Colleague

>Am I declaring it the wrong way or something?
You've just given a classic example of misunderstanding pointers. Just because you've defined a pointer doesn't mean you can use it right away. You have to point it to a suitable block of memory first. Right now your listHolderPtr is indeterminate. It could point anywhere, and hopefully it points somewhere that'll crash immediately when you dereference it rather than linger until it's painfully expensive to fix the problem.

Narue 5,707 Bad Cop Team Colleague

>For some reason, it crashed right here.
The only reason for a crash there is if listOfLists can't be dereferenced (if it's NULL, for example).

Narue 5,707 Bad Cop Team Colleague

No. Read our rules about keeping help on the site.

Narue 5,707 Bad Cop Team Colleague

>That's working but if the idea is a bad one , let me know :-)
It's not my job to hold your hand. If you're not confident enough in your code, then rewrite it until you are.

>What site are you talking about?
>is the recursive function the if inside the do...while?
Ignore mohanrobin. He's just spouting nonsense.

Narue 5,707 Bad Cop Team Colleague

Your code shouldn't compile at all because you haven't terminated the structure definition with a semicolon.

>date.d = atoi(str_date.substr(0,2).c_str());
>date.m = atoi(str_date.substr(2,3).c_str());
>date.y = atoi(str_date.substr(4,7).c_str());
substr doesn't use a begin/end pattern, it uses a begin/count pattern. The second argument should be 2, 2, and 4 for those three lines, respectively.

>The while condition is causing my program to crash when str_date.length()==0 (I think)
You think correctly. You're breaking from the loop when the string is empty and then you proceed to access the nonexistent elements of the string with your calls to substr.

Narue 5,707 Bad Cop Team Colleague

>Thanks for the great writnings guys.
Yep, no doubt we saved you a lot of time and effort doing actual research and coming up with your own opinions.

Narue 5,707 Bad Cop Team Colleague

>what/where could I use a hash table (chaining?) in my program.
That's ass backward. It's a solution looking for a problem, not a problem looking for a solution.

Narue 5,707 Bad Cop Team Colleague

>I'm using TC++ 3.0.
Why?

>I think that the compiler is faulty.
And? Salem agreed with you if the code you posted is exactly the code you're running. What more are you looking for?

Narue 5,707 Bad Cop Team Colleague

>Both methods throw an exception if you try to enter something other than an integer.
How do you figure that? Only the second will actually throw an exception. The first will simply set cin to an error state (in which case the ignore will effectively be a no-op).

Narue 5,707 Bad Cop Team Colleague

>you think that using a modulus in this case would cause a problem?
No, I think reading integers would cause a problem.

I'm going to quote your PM to me as it has no business being sent to me privately and should have been in this thread.

Thanks for the help with my issue. I have another question for you now that I have use your method of calling my numbered pair the begining of what I wrote is craping out. My entire data file is structured as such
707 141251 141659
321 090537 090748
319 101502 102929
222 105702 110000
305 114202 115111

what I am getting now is 70:7:14:12:51 and so forth. Is there a way to clean this up?

The bad news is that even if you were reading integers, it still wouldn't work due to the whitespace. What you probably want to do is compact the whitespace after reading a whole line, the use a stringstream to complete the solution:

#include <cctype>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>

int convert ( const char *s )
{
  int result = 0;

  // Assuming unsigned single or double digit values
  while ( *s != 0 )
    result = 10 * result + ( *s++ - '0' );

  return result;
}

void compact ( char *s )
{
  char *p = s;

  while ( *s != '\0' ) {
    if ( !isspace ( *s ) )
      *p++ = *s; …
Narue 5,707 Bad Cop Team Colleague

>Wasn't that one of the thoughts behind COBOL.
Something like that. I think the idea behind COBOL was to design a programming language similar to English so that people could pick it up and use it more easily. Of course, my experience with COBOL says that the experiment failed.

>these programming languages would be like everyday english
That's been tried already.

>where we can just tell the computer what to do by just coding in plain english!!!
Impossible. Plain English (and even proper English) is far too ambiguous to be used as a programming language. Any language based on English would have its own rules separate from English and any benefit of using "plain English" is lost with the new rule set. It's more likely that a form of component programming will develop, where small building blocks are put together to form larger building blocks and at a certain level of abstraction, we don't really do more than slap a few blocks onto a palette. That's basically what we're doing now (a great example of the idea is Forth), but instead of writing code, we would work with blocks that generate code behind the scenes. Much of Visual Studio's drag and drop GUI design features this concept as well.

Narue 5,707 Bad Cop Team Colleague

>This is a math problem.
No, it's not. Reading the data as an integer strikes me as dangerous in this case. I can easily see integer overflow being a potential problem, and that serious affects the robustness of the code. Something like this would be better:

#include <fstream>
#include <iomanip>
#include <iostream>

int convert ( const char *s )
{
  int result = 0;

  // Assuming unsigned single or double digit values
  while ( *s != 0 )
    result = 10 * result + ( *s++ - '0' );

  return result;
}

int main()
{
  std::ifstream in ( "mydata" );

  if ( in ) {
    char buffer[3];

    while ( in>> std::setw ( sizeof buffer ) >> buffer )
      std::cout<< convert ( buffer ) <<':';

    std::cout<<'\n';
  }
}

That way the input method forces integer pairs and avoids the potential overflow. It also greatly simplifies the math (or eliminates it entirely if you choose not to do a manual conversion).

Narue 5,707 Bad Cop Team Colleague

>So, by now it seems like C++ will be the futures programming language.
Why? If it really seems that way then you should be able to point out a list of convincing reasons.

>But what do you think of the future of programming languages??
I don't really care. As programming languages, tools, and techniques evolve, I'll adapt. I don't need to try to predict the future to do that.

>Will it be easier and better for the user to use it and handle it?
By "user" I assume you mean programmer, because users don't want to write software, otherwise they'd be programmers. And yes, the trend is for languages to be dumbed down such that it's easier for the lowest common denominator to write code without actually learning how to do it properly[1].

>Write down every thing about programming language that pops up on your mind!
So that you can take our words and use them as your own? Your post reeks of data mining for homework answers.

[1] I say this with C# 3.0's new features in mind. The implicitly typed variables are about half a step away from insanity.

Narue 5,707 Bad Cop Team Colleague

>since i do not have any Industrial Experience..
It's a final year project. Just pick something you learned that exhibits your newfound skills and seems interesting. It doesn't have to be practical or viable in the market, so asking for advice from people with "Industrial Experience" is silly.

Narue 5,707 Bad Cop Team Colleague

If a number is divisible by 2, it's even. If it's not divisible by 2, it's odd. You can find out if a number is divisible by 2 by finding the remainder of division by 2. C++ has a remainder operator, %. So it stands to reason that if you have a number x, you can say:

if ( x % 2 != 0 ) {
  // The number is odd
}

Ne?

Narue 5,707 Bad Cop Team Colleague

>int iProduct;
You're using iProduct without initializing it.

while (iNumber <= iCount)
	iProduct *= iNumber;
	iNumber++;

C++ isn't Python. 99% of the time, whitespace means bupkis, absolutely nothing. If you have a loop or conditional with more than one statement, you must wrap those statements in parentheses:

while (iNumber <= iCount) {
	iProduct *= iNumber;
	iNumber++;
}
Narue 5,707 Bad Cop Team Colleague

Check your spelling, check the number of arguments, check the type of arguments, and if none of that works, make a tiny program that exhibits the problem so that we can actually compile and link it ourselves instead of trying to decipher the snippets that you think are relevant.

Narue 5,707 Bad Cop Team Colleague

>I created a Fibonacci Sequence array and tried to
>apply the same thinking to the factorial program
That's a beautiful approach. Take a problem you've already solved and morph it into something similar that solves your current problem:

#include <stdio.h>

int fibonacci ( int n )
{
  int last = 0;
  int curr = 1;
  int next;

  if ( n < 2 )
    return n;

  while ( --n >= 1 ) {
    next = last + curr;
    last = curr;
    curr = next;
  }

  return next;
}

#define LIMIT 10

int main ( void )
{
  int save[LIMIT];
  int i;

  for ( i = 0; i < LIMIT; i++ )
    save[i] = fibonacci ( i );

  for ( i = 0; i < LIMIT; i++ )
    printf ( "%d ", save[i] );

  printf ( "\n" );

  return 0;
}

Just because you couldn't figure it out doesn't mean that you don't have a promising thought process. I think you'll be a pretty good programmer if you keep at it. :)

Narue 5,707 Bad Cop Team Colleague

>What does the operator *= mean?
It means you should check your C reference. Not many people like to explain things that are easily discovered by looking in a book or searching google. In this case, *= means multiply and assign using the left hand operand as the left operand of the multiplication. It's functionally equivalent to this:

prod = prod * k;
Narue 5,707 Bad Cop Team Colleague

>what I should enter in the code where you have written the word factorial?
That's a function. You don't have to write a function, but you do have to loop from 1 to n and store the running product to calculate a factorial. Something like this is a translation of the formula into code:

int prod = 1;
int k = 1;

while ( k <= n )
  prod *= k;
Narue 5,707 Bad Cop Team Colleague

>Well, the math formula reads, for example:
Actually, it's more like: n! = \displaystyle\prod_{k=1}^nk, but yours is close enough. However, knowing the formula doesn't mean you can write the code to implement it. Can you write a function that when given a value of n, produces the factorial of n? My point is that calculating n! is independent of what you do with the result. If you have a function that gives you n!, you can store it in an array just as easily as printing it:

int fac[10];
int i;

for ( i = 0; i < 10; i++ )
  fac[i] = factorial ( i );

for ( i = 0; i < 10; i++ )
  printf ( "%d\n", fac[i] );
Narue 5,707 Bad Cop Team Colleague

>Example: If i convert a base 10 number (255) to base 2 i get 11111110;
I repeat. My testing does not show this behavior. If I run your program (exactly as posted), type 255 for the value, 10 for the input base, and 2 for the output base, the result is printed as 11111111. Your example is faulty, or your description of how to reproduce the program is faulty.

Narue 5,707 Bad Cop Team Colleague

So...when doesn't it work? So far you've given me one example that doesn't work for you but does work for me, and one example that works for you. An example that doesn't work for both of us would expedite the troubleshooting process just a smidge.