Narue 5,707 Bad Cop Team Colleague

>can you post the code?
No, because this thread is two years old.

Narue 5,707 Bad Cop Team Colleague

>i dont know how to reverse the string in memory
How would you reverse "a"? Do nothing, clearly because the reverse of "a" is "a". What about "ab"? Mightn't you just swap the characters like this?

char save = str[0];
str[0] = str[1];
str[1] = temp;

Keep adding more characters and see how you would swap them around to reverse the string until you find a pattern. That's your algorithm for an in-place string reversal.

Narue 5,707 Bad Cop Team Colleague

>are vampires really undead?
Last I checked they were on the list of traditional undead creatures. I guess it depends on which definition you go with, but most of the time you have to die first before becoming a vampire.

Narue 5,707 Bad Cop Team Colleague

Hmm, interesting that your problem is comparing strings. In this case you would use strcmp:

if ( strcmp ( buffer, "terminate" ) == 0 ) {
  // Notify the other program of termination
  return 0;
}
Salem commented: You'd think someone who managed IPC could have figured out strcmp() - Salem +6
Narue 5,707 Bad Cop Team Colleague

Post your code so far so that I know what language and language features you're using for your strings and I'll be happy to show you.

Narue 5,707 Bad Cop Team Colleague

If you're in main and not some nested function call you can simply return and the program will end. Otherwise, there's a function called exit in stdlib.h that does the same thing from anywhere in the program. Do you know how to take a string as input and compare it with another string?

Narue 5,707 Bad Cop Team Colleague

>So I feel this is right place to post.
I feel that your first post was in the right place. If someone wants to add the C or C++ relevant links from that site to our resources sticky, that's fine. Otherwise, cross posting the same thing to multiple forums is not acceptable.

Narue 5,707 Bad Cop Team Colleague

I don't have a problem with the link, but please don't cross post it again.

Narue 5,707 Bad Cop Team Colleague

>What exactly is this line doing?
It's using a character in the string as an index into the saved array and incrementing the value stored there. The values start at zero, so you're basically counting how many of each character is stored in the string. Let's say for the sake of brevity that a char can only hold the numbers 0 through 5 and the string contains "1515325". The saved array starts out like this:

[0][0][0][0][0][0]

Going into the loop, we use each number in the string as an index into the saved array. After the loop is done, the saved array looks like this:

[0][2][1][1][0][3]

saved[1] is 2 because the string has two 1's, saved[5] is 3 because there are that many 5's in the string, and saved[2] and saved[3] are both 1 for the same reason. That's a frequency table. The value you want a frequency of is used as an index and the value stored in the table represents how many times it occurs.

The problem with a frequency table like this is that the table has to be as big as all of the possible values. For small ranges like the latin alphabet or even the ASCII character set, that's okay. An array of 256 values isn't a big hit, but if you have millions or billions of values in the range, it becomes more of an issue for storage.

>How big should I define CHAR_MAX?
CHAR_MAX is a standard …

Narue 5,707 Bad Cop Team Colleague

Here's some more feedback from a less sophisticated user. ;) I've noticed that the bread crumbs are missing the forum index in annoying places like the control panel. I have to back up or go to the home page (or hit my bookmark) to get back to the index when I don't recall needing to do that before.

Narue 5,707 Bad Cop Team Colleague

>what undead thing would you be?
What are our choices? Most people liken 'undead' to 'vampire', and there are so many definitions of a vampire that it's hard to choose them. You might end up with some inconvenient weaknesses. A lich is usually pretty badass, so I might pick that one.

>what would you do?
Have fun, of course. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

1) You need to be skilled enough to complete the project you bid on.
2) Last I checked it was almost always PayPal.
3) Probably not that much compared to a typical freelancer or salaried programmer. The price for projects will vary wildly depending on the complexity or difficulty, so if you choose well and bid well, you'll make decent money.

Narue 5,707 Bad Cop Team Colleague

>can...u...convert..words..2..no..?????
Yes, though the inverse is easier due to formatting constraints. It's not a trivial problem, but it's also not overly difficult. What have you tried?

Narue 5,707 Bad Cop Team Colleague

I hope that your code isn't supposed to be valid C, because it's not.

>But he wanted me to give a solution without using 2 - dimensional arrays.
Well, you can do it with a frequency table, which is essentially a one dimensional array:

char FirstNonRepeated ( const char *str )
{
  // unsigned char for space efficiency
  unsigned char saved[CHAR_MAX + 1] = {0};
  size_t i;

  // Build the frequency table
  for ( i = 0; str[i] != '\0'; i++ )
    ++saved[str[i]];

  // Return the first character with no repeats
  for ( i = 0; str[i] != '\0'; i++ ) {
    if ( saved[str[i]] < 2 )
      return str[i];
  }

  return '\0'; // No non-repeated chars
}

In C++ I would expect to see you use a map or hashmap, and if you used an array I would ask you to defend your decision. If you used a map or hashmap I would ask you to defend your decision too, so don't read into that. In an interview we try to get a good feel for how your brain works. ;)

You can also solve the problem in a less elegant manner using nested loops:

char FirstNonRepeated ( const char *str )
{
  size_t i;

  for ( i = 0; str[i] != '\0'; i++ ) {
    // Find any repeats
    int is_repeated = 0;
    size_t j;

    for ( j = 0; str[j] != '\0'; j++ ) {
      // Make sure the character skips itself …
Aia commented: I learned with this example +1
Narue 5,707 Bad Cop Team Colleague

>I am on Windows xp professional edition and looking for a free
>develeopment tool/ide for some self c++ learning.
Most of the good compilers come with an IDE and are freely available.

>but it is still beta version and I want something stable.
I haven't noticed any instability in the beta version of Dev-C++.

>I want a package which hopefully contains all the compilers+libraties+debugging tool
>etc. so that after the installtion I am just ready to write and run.
I usually recommend either Turbo C++ (the new one, not the crappy ancient one) or Visual C++ 2005 Express.

Narue 5,707 Bad Cop Team Colleague

>but, not naming names
Examples are good for striking a point home to those who haven't experienced what you're talking about. Not naming names is a silly way to make yourself look nice when you complain about other people.

>I have no Earthly clue how and why they are still active and seemingly favored
Clearly they have some redeeming qualities that you haven't noticed or are incapable of recognizing.

>Personally, I would have cut them after the second warning
If you have specific grievances, sitting on them just makes you bitter. Nothing will happen if you don't voice your complaints in such a way that the problem can be dealt with (ex. reporting the people in question). Whining about people who "know who they are" is completely unproductive.

Narue 5,707 Bad Cop Team Colleague

>I cannot figure out why I am getting these two errors
Try reading them. The first is pretty specific about what the problem is.

Narue 5,707 Bad Cop Team Colleague

If you're writing too much for the quick reply box, maybe, just maybe, you should be using the advanced reply page. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>what is bioskey()
An obsolete function that some old compilers support.

>what does it do
It sends the 16h interrupt so that you can get direct keyboard access without using inline assembly.

>and how to use it?
Don't. It probably won't work anymore and there are better ways to get similar effects using system APIs.

Narue 5,707 Bad Cop Team Colleague

>it wouldn't be surprising for sizeof(char) to be 1, yet that it would be 32 bits?
Sure, why not?

>Or is it determined by the actual implementation of your C library?
It's determined by the compiler, not the library. Internally, a compiler will typically match the hardware for performance reasons, and the library would be written to match the compiler.

Narue 5,707 Bad Cop Team Colleague

>so are you normal in real life then?
It depends on what you would call normal...

Narue 5,707 Bad Cop Team Colleague

>Do i need to declare another iterator to traverse the rows and another one to traverse each elements?
Yes. Each row is an independent data structure, so you have no choice but to use two iterators. It's exactly the same as when you build the vector of vectors:

#include <iostream>
#include <iomanip>
#include <vector>

int main()
{
  std::vector< std::vector<int> > v;

  for ( int i = 0; i < 10; i++ ) {
    v.push_back ( std::vector<int>() );

    for ( int j = 0; j < 10; j++ )
      v[i].push_back ( i + j );
  }

  std::vector< std::vector<int> >::iterator row_it = v.begin();
  std::vector< std::vector<int> >::iterator row_end = v.end();

  for ( ; row_it != row_end; ++row_it ) {
    std::vector<int>::iterator col_it = row_it->begin();
    std::vector<int>::iterator col_end = row_it->end();

    for ( ; col_it != col_end; ++col_it )
      std::cout<< std::setw ( 3 ) << *col_it;
    std::cout<<'\n';
  }
}
John A commented: Glad to see you're posting on DaniWeb again! - joeprogrammer +6
Narue 5,707 Bad Cop Team Colleague

>Byte is not defined as 8 bits then what is it defined as?
It's defined as whatever the implementation wants. The standard only specifies that sizeof ( char ) be 1, and at least 8 bits. That happens to be the most common definition of a byte, but systems other than your PC also support C and don't have the same definition.

Narue 5,707 Bad Cop Team Colleague

>How will I use this?
Wrap it in a class. It's much easier to use that way:

#include <ctime>

class jsw_timer {
public:
  typedef double diff_type;
public:
  jsw_timer(): start ( std::clock() ), elapsed ( 0.0 ) {}
public:
  void begin() { start = std::clock(); elapsed = 0.0; }
  diff_type end() {
    elapsed = static_cast<diff_type> ( std::clock() ) - start;
    return elapsed /= CLOCKS_PER_SEC;
  }
  diff_type last() const { return elapsed; }
private:
  std::clock_t start;
  diff_type    elapsed;
};
Narue 5,707 Bad Cop Team Colleague

>I would love to see how Narue answers this question.
I'm completely different here than in real life. The anonymous nature of the web makes it much easier to experiment with different ways of expressing yourself without risk.

Narue 5,707 Bad Cop Team Colleague

>Scroll down for the answer.
Translation: The answer is silly.

>THE CHAIR
Ding ding ding! Narue gets a cookie. :rolleyes:

>Which chair do you like to recommend?
I don't recommend subjective office equipment. The chairs I like may not be good for other people and vice versa. For example, people go on and on about how the Aeron chair is an orgasmic experience, but I hated it. Why not sit in a few and figure out what styles suit you?

Narue 5,707 Bad Cop Team Colleague

>And I'm only going with the boy/girl guess based on the name.
And I wouldn't be so cruel as give a boy a girl's name.

>Will she return to daniweb after the baby or will she take a while out?
I lurk when I have a spare moment, but Daniweb is a very low priority at the moment, and will probably continue to be for quite a while.

Narue 5,707 Bad Cop Team Colleague

>it is very clear that is no one can help me
When you ask such incoherent questions, it should be obvious that no one can help you.

Narue 5,707 Bad Cop Team Colleague

>the OP should have asked a different question to match your answer!
Yea! How dare he not tailor his question to my answer! Jeez, these people sure are arrogant and presumptuous. ;)

Narue 5,707 Bad Cop Team Colleague

The only problem with being right all of the time is that people really let you have it when you make a mistake. ;)

Narue 5,707 Bad Cop Team Colleague

>My header file time.h is being corrupted..
Dare I ask how you managed that?

>I can't find it on the internet...
It's an implementation header. Reinstall your compiler, because you can't just ask someone to paste theirs and expect it to work.

Narue 5,707 Bad Cop Team Colleague

No, I'll get it included in the package as a Microsoft Partner.

Narue 5,707 Bad Cop Team Colleague

We're not going to do it for you. Please try it yourself and see what you can come up with. You'll learn more that way. Also, the algorithm is called QuickSelect, if you want to do some research on it.

Narue 5,707 Bad Cop Team Colleague

That's an admirable goal. You'll probably want a good book (I recommend Accelerated C++), a good compiler (Visual C++ 2005 Express is good and easy to use and it scales well as you learn), and a good community (such as this one) to help you with tougher problems.

Narue 5,707 Bad Cop Team Colleague

>Actually she was quoting something else so I was thinking that.
Actually, I didn't look at the code closely enough, so my conclusion didn't match the quote. This is one of the rare cases where I was completely wrong. ;) I think in the future I'll refrain from answering programming questions while waiting to zone in EQ2. :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>There's only one private function in B. What made the size to be 4?
Member functions don't generally apply toward the size of an object. If they do, I would question the quality of your compiler. The thing that made the size be 4 is the internal object stuff that C++ does behind your back, in this case, probably the pointer for a virtual table..

SpS commented: Nice ~~SunnyPalSingh +3
Narue 5,707 Bad Cop Team Colleague

>one problem i m getting is it's only reading 19 numbers (0 to 19)
If you're only expected to read up to 20 numbers, that's correct. 0 to 19 is exactly 20 numbers.

>and the rest i think u can see from the output (preety messed up)
Reading from a file is pretty straightforward and consistent between applications. It follows this logic:

open the file

while there are more records
  read one record
  process one record
loop

print statistics if any
print saved records if any

close the file

In your case a record is one number, so you would convert that logic into C++ like so:

//open the file
ifstream in ( "numbers2.txt" );
int record;

//while there are more records
//read one record
while ( in>> record ) {
  //process one record
  if ( record < 0 )
    Neg[NegCount++] = record;
  else if ( record == 0 || record % 2 == 0 )
    Even[EvenCount++] = record;
  else
    Odd[OddCount++] = record;
}

//print statistics if any
cout<<"Negatives: "<< nNegatives <<'\n';
cout<<"Evens: "<< nEvens <<'\n';
cout<<"Odds: "<< nOdds <<'\n';

//print saved records if any

//ifstream closes the file from the destructor

Since you'll probably be storing the numbers in one of the three arrays that you commented out, you only need a single int for holding the record.

Narue 5,707 Bad Cop Team Colleague

>I really think this should just work.
It takes work to get things to work. Your pieces don't fit together because you don't define functions. The default constructor, destructor, and operator>> are never given bodies. That's the core of your problem.

Narue 5,707 Bad Cop Team Colleague

>The last node(s) will always have two free child positions, won't it?
A full tree in this case is one where every non-leaf node has two non-null children. For example:

a
     /   \
    b     c
   / \   / \
  d   e f   g

is a full tree, but

a
     /   \
    b     c
     \   / \
      e f   g

is not because b is neither a leaf nor has two non-null children.

Narue 5,707 Bad Cop Team Colleague

>i dont know how to write the code ?
Do you know how to do a preorder traversal? Once you have that, it's just a test whether both children are either null or not null. It's a short solution, so I can't give you example code without solving the problem for you.

Narue 5,707 Bad Cop Team Colleague

>Are you married or not ?
Yes. ;)

>If yes then what did marriage change in your life, are the new found
>responsibilities burdening you or making you a better person ?
What didn't it change? :rolleyes:

Narue 5,707 Bad Cop Team Colleague

>I downloaded the microsoft visual studio and it confused the hell outa me.
Anything will at first. Either you have to deal with the complexity of an IDE (that's a compiler, debugger, editor, etc.. all rolled up into one graphical application), or the complexity of learning command line tools. You should learn both, but starting with an IDE will probably be easier. Since you already have Visual Studio, I can walk you through setting up a project and testing it.

Step 1) Go to File->New->Project
Step 2) From the project templates list, choose Empty Project[1]
Step 3) Type in whatever name you want for the project and hit OK
Step 4) Look for the Solution Explorer[2] and right click on the Source Files folder
Step 5) Choose Add->New Item
Step 6) From the templates list, choose C++ File (.cpp) and call it something like main, then click Add. Now the text editor has a text file in it called main.cpp.
Step 7) Paste this code into the editor:

#include <iostream>

int main()
{
  using namespace std;

  cout<<"Hello, world!\n";
}

Step 8) Type ctrl+F7 to compile the code
Step 9) Type ctrl+F5 to run it

After the project is set up, the work is minimal. If you want, you can just reuse the same project until you're more comfortable with the IDE. :)

>what is a compiler?
Simple answer: A compiler turns your source code into a working …

Narue 5,707 Bad Cop Team Colleague

Just FYI, this thread is over a year old.

Narue 5,707 Bad Cop Team Colleague

Printing in .NET is funky, but simple. Once you get the hang of it it's no problem, but that first hurdle is figuring out how the heck the parts all fit together. Printing multiple pages is handled inside the PrintPage event handler. The handler selects which page to print and also notifies the print controller whether more pages exist with e.HasMorePages. Let's say you get your info from records in a data table. You could use a Page variable as an index into the data table, and when it reaches MaxPages, you set e.HasMorePages to false. My VB is kind of weak right now, so here's some C#:

private int _page;
private int _maxPage;
private PrintPreviewDialog _preview = new PrintPreviewDialog();
private PrintDocument _document = new PrintDocument();

public MyClass()
{
  //...
  _document.PrintPage += PrintPage_Handler;
}

public void PrintAll()
{
  _page = 0;
  _maxPage = _dtMaster.Rows.Count;
  _preview.Document = _document;
  _preview.ShowDialog();
}

private void PrintPageHandler( object sender, PrintPageEventArgs e )
{
  // Get info to print (name, address)
  string name = (string)_dtMaster[_page]["Name"];
  string addr = (string)_dtMaster[_page]["Address"];

  // Draw the strings
  //...

  e.HasMorePages = ++_page < _maxPage;
}

Using the preview dialog instead of the print dialog will save you paper while testing. ;)

Narue 5,707 Bad Cop Team Colleague

>return(intFirst, intSecond, intThird);
This doesn't actually return three values, it just seems that way because intFirst, intSecond, and intThird are global. What this expression actually does is evaluate (and subsequently ignore) all but intThird, which it then returns. So only intThird is returned, but because all of them are global, you can still access them in main and the values won't disappear.

Narue 5,707 Bad Cop Team Colleague

>It could also be interpretated that Salem has so much free time on his
>hands he can afford to join every c forum in existence.
Please. Everyone knows that Salem is a bot. ;)

Narue 5,707 Bad Cop Team Colleague

>Huh? Whatcha mean?
He means that this question has been spammed on multiple website forums, such as Daniweb, cprogramming, etc...

Narue 5,707 Bad Cop Team Colleague

>When i try to put code on forum it changes it.
Ah, gotcha. I thought you were talking about Visual Studio. :lol: Anyway, the single biggest culprit when it comes to formatting is tabs. If you use tabs instead of spaces for indentation, they may not be translated correctly when posting code.

Narue 5,707 Bad Cop Team Colleague

I posted a image of my code.

So I see. But I don't understand what you mean by "It keeps changing my code". You have one syntax error in the image you posted, and that's using b-F(); instead of b->F();. Notice the missing angle bracket that completes the arrow operator. Beyond that, I have no idea what you're trying to ask. :(

Narue 5,707 Bad Cop Team Colleague

>i don't know if that's the rite procedure.
The string class is designed to act like a first class type, so the operations you use on numbers should work for string objects as well. There are a few problems with your code though.

>int nTemp;
nTemp is the temporary storage for the item you save. Since you're saving a string, ntemp should be defined as a string:

string nTemp;

>for (int iCv = 1; iCv < nLength; ++iCv)
One of the things you need to keep in mind with for loops is if you declare the counter in the loop, you can't use it after the loop. If you need iCv after the loop ends (which you do), it has to be defined outside of the loop:

int iCv;

for (iCv = 1; iCv < nLength; ++iCv)

>for (int k = iCv-1; k >= 0 && arnList[k] > nTemp; k--)
Ditto here. You use k after the loop, so it can't be defined inside the initialization clause.

The fixes are minor. All in all, you were very close to a working solution. :)

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

int main()
{
  string arnList[9]={"John", "Dave", "Steve", "Kevin","Andrew","Scott","Colin","Timothy","Zenon"};
  int nLength=9;
  string nTemp;
  int iCv;

  for (iCv = 1; iCv < nLength; ++iCv)
  {
    //the new value to be inserted into a temporary location 
    nTemp = arnList[iCv];
    // k is the index of the number to the left of the iCv.
    int …