Narue 5,707 Bad Cop Team Colleague

Build it manually:

#include <iostream>
#include <string>

int main ( int argc, char *argv[] )
{
  std::string args;

  for ( int i = 0; i < argc; i++ ) {
    args += argv[i];

    if ( i != argc - 1 )
      args += ' ';
  }

  std::cout<< args <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>what if i don't want to use it (since it is optional)?
Provide a suitable default. For example, with GCC if you don't provide the executable name, a.out is used as the default.

Narue 5,707 Bad Cop Team Colleague

You only perform the copying steps if the search string is found. Add a "not found" case where the line is copied as-is if the search string isn't located.

Narue 5,707 Bad Cop Team Colleague

>#define p printf
This is an extremely bad idea. If your teacher taught it to you, slap him for me.

>clrscr();
This is a bad idea. Not only is it anti-social (by removing the output of other programs when run in a shared console), it unnecessarily destroys the portability of your code.

>while(a>=1)
First, a doesn't have a predictable value. Second, how are you expecting to count from 1 to 100 with that condition?

>for(a>=0) p("%d",a);
I can't begin to guess what you were thinking here.

Here's a tip, and this is what I personally do when writing a new program, write out a bare bones main function with <stdio.h> and then add to it. Here's the bare bones code that I start with:

#include <stdio.h>

int main ( void )
{
  return 0;
}

Now add the parts you need. For example, you know you want to print the sum of 1 to 100, right? So add the framework for doing that:

#include <stdio.h>

int main ( void )
{
  int sum = 0;

  // Sum 1 to 100

  printf ( "The sum is %d\n", sum );

  return 0;
}

The point of this iterative approach is that you can test at every point. You can verify that your program prints the sum (even if it's always zero) at this point. At the previous point you could verify that the program runs and terminates properly. Now for the loop:

Nick Evan commented: great help for this newbie +9
Narue 5,707 Bad Cop Team Colleague

>but that is 12 bytes right? I need 12 bits.
Sorry, I misread your question. The smallest block of addressable memory you can use is a byte. If you need a bit count that isn't an even multiple of the byte size, you can either read "too much" and carry over the excess to the next operation using bitwise operators, or change your design to better fit the system.

>And should I open the file as ios::binary or not?
Yes, you should. That way you guarantee that textual conversions are not performed when you read the binary part. I imagine it's more important for the binary data be read correctly than the ASCII data. And you can always do manual newline conversions in the ASCII data if you need to.

Narue 5,707 Bad Cop Team Colleague

In other words, part of the file is ASCII and the rest is binary data.

>Can I do the above (ie. read with getline() and then read binary?
Sure, but you may encounter problems with newline conversion.

>How would I read 12 bits at a time (for a 12-bit color image)?
Use an array of 12 char:

char buf[12];

infile.read ( buf, sizeof buf );
Narue 5,707 Bad Cop Team Colleague

I mean this is a public forum, and we get wannabe hackers all the time. Regardless of your intentions, the chances of somebody taking the lessons from such a discussion and using them for illegal purposes are right at 100%.

In light of that (barring being overridden by happygeek or Dani), my official response is that you can debate legality all you want, but any discussion of implementing a keylogger on Daniweb would be a violation of Keep It Legal.

Narue 5,707 Bad Cop Team Colleague

>What is yours oppinion about that issue?
I think this is identical to discussion of writing a virus for instructional purposes. The direct intention may be benign, but ultimately it's so prone to being used illegally that Daniweb's rules come into play. Thus, discussion of keylogger implementation is prohibited.

Narue 5,707 Bad Cop Team Colleague

>I need to store all messages during the chat sessions among users.
Is this some ad hoc chat program that doesn't support logging?

Narue 5,707 Bad Cop Team Colleague

>Still doesn't recognize MessageBox() though.. I thought it didn't require any header files?
You thought wrong. You need to make sure that windows.h is included and that you're linking to either user32.lib or user32.dll.

Narue 5,707 Bad Cop Team Colleague

>so for a telephone directory will it be appropriate to use strcmpi() or stricmp() ?
That's a reasonable requirement.

Narue 5,707 Bad Cop Team Colleague

Python is friendly and relatively painless.

Narue 5,707 Bad Cop Team Colleague

>Do anyone know if a someones privacy rights have been infringed if a
>signed document has been scanned and uploaded onto a website at all?
I'd say if a signature was required on the document, it falls under the category of potentially sensitive.

>what would be a good way to disguise the signature on a declaration document?
Run it through a redaction process to black out the signature and any other potentially sensitive information.

Narue 5,707 Bad Cop Team Colleague

That's a good start, but you aren't taking into account the rest of the data on the line. What you need to do is a string replacement, which involves copying everything before the search string to a buffer, append the replacement string, then everything after the search string. Depending on the length of the search string, you may need to grow the buffer so the final line will fit.

Example:

"This is a test" -> replace "is"
Copy "This " to the buffer: "This "
Append "***is***" to the buffer: "This ***is***"
Append " a test" to the buffer: "This ***is*** a test"

The code isn't terribly difficult, but dealing with all of the memory situations can be tedious. See what you can come up with.

Narue 5,707 Bad Cop Team Colleague

>in the underlined part, by greater value does it mean that A has greater value than B?
strcmp compares each character in order and returns the result of the first two characters that don't match. It's equivalent to this implementation:

int jcmp ( const char *a, const char *b )
{
  while ( *a == *b && *a != '\0' ) {
    ++a;
    ++b;
  }

  if ( *a < *b )
    return -1;
  else if ( *a > *b )
    return +1;

  return 0;
}

The final comparison is a direct comparison of the underlying integer value for the two characters. So "a" will be greater than "A" under ASCII because 'a' has a value of 97 and 'A' a value of 65.

This can sometimes be confusing if you're expecting comparisons for a natural ordering rather than lexicographical ordering by the underlying character set.

Narue 5,707 Bad Cop Team Colleague

>can anyone tell me how to make it so the PC doesn't use 100% cpu?
It uses 100% CPU because you're using a busy loop to pause. A true fix for the problem is "don't do that". Use some form of pause that puts the thread to sleep without affecting the other running threads. Unfortunately, there's no standard way to do that, so you'll need to look to your implementation and OS for libraries that support what you need.

For example, on Windows you might do this:

#include <stdio.h>
#include <windows.h>

int main ( void )
{
  printf ( "Delay for three seconds\n" );
  Sleep ( 3000 );
  printf ( "Done!\n" );
}
Narue 5,707 Bad Cop Team Colleague

>for misunderstanding the concepts of classes
That's hardly cause for an apology.

>is it really only to reuse code?
Classes are an organizational tool, nothing more. There are many, many ways you can use that tool to achieve many, many results, but at the core classes are just another way of structuring your code.

Narue 5,707 Bad Cop Team Colleague

>ok well yea how about something a lil bit easier
I like how you ask for something easier then post code of equivalent complexity.

Narue 5,707 Bad Cop Team Colleague

>can any one make me a computer operating system
Sure, go here and help yourself.

Narue 5,707 Bad Cop Team Colleague

Well, since you want to convert to little endian, I'll assume you have something in big endian format already. If that's the case it's a simple matter of reversing the bytes. For example:

void bswap ( unsigned int x )
{
  x = ( x >> 24 ) | ( ( x << 8 ) & 0x00FF0000 ) |
    ( ( x >> 8 ) & 0x0000FF00 ) | ( x << 24 );
}

Though ntohl and htonl are generally a better option if they're available.

Narue 5,707 Bad Cop Team Colleague

Here's something to play with as a template:

#include <ios>
#include <iostream>
#include <limits>
#include <string>

using namespace std;

int main()
{
  bool done = false;

  do {
    int value;

    cout<<"Enter a number: ";

    if ( !( cin>> value ) )
      break;

    cout<<"You entered "<< value <<'\n';

    // Clean up leftover garbage
    cin.ignore ( numeric_limits<streamsize>::max(), '\n' );

    string option;

    cout<<"Continue? (y/n): ";

    if ( getline ( cin, option ) && option != "y" )
      done = true;
  } while ( !done );
}
Narue 5,707 Bad Cop Team Colleague

>Your right to a very small degree
That's a pretty arrogant statement, all things considered.

>But its still about 1000% faster.
Not on my system. I show a complete reversal of the timings, which means your code is also non-portable. Fancy that.

>I suppose a more in depth explanation could have been due earlier
Too late, you fail.

>but I didn't expect my code to face such scrutiny
You were planning on using that code essentially to prove that your instructor is incompetent. I have trouble seeing how not only you didn't expect close scrutiny by someone, but that you were also so sloppy as to completely fail such scrutiny both in describing the purpose of the code and writing the code itself.

>But I suppose it's appreciated ;)
Bite me. Nothing irritates me more than people dismissing my contributions with a smarmy comment. Don't expect any help from me in the future.

Narue 5,707 Bad Cop Team Colleague

Do you actually want to convert to little endian or is this some kind of homework project? Because converting to hexadecimal doesn't enter into the picture if you're working with the bytes. The representation only matters for display and such.

Narue 5,707 Bad Cop Team Colleague

C is case-sensitive. The name you use in the function definition must match the name in the prototype exactly. Spelling, capitalization, everything. I usually just copy and paste; it's easier to get right every time that way.

Narue 5,707 Bad Cop Team Colleague

You have three distinct problems.

1) You need to use square brackets instead of parentheses when dynamically allocating memory:

// Square brackets!
name = new char[strlen ( foo ) + 1];

2) You need to use the syntax for delete that matches the syntax for new:

base::~base()
{
  cout<<name<<"destructor called"<<endl;
  delete [] name;
}

3) You need to remember that assignment is different from copy construction. The following is all assignment:

t1 = b1;
t2 = b2 ;
t3 = b1+b2;

Yet you haven't defined an assignment operator. You can make it work by changing it to copy construction:

base t1 = b1;
base t2 = b2 ;
base t3 = b1+b2;
Narue 5,707 Bad Cop Team Colleague

The problem is a faulty flux capacitor on line 42.

Narue 5,707 Bad Cop Team Colleague

Were you just screwing with us, iamthwee? :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>i am sorry
For what?

Narue 5,707 Bad Cop Team Colleague

>I'm sorry if a 1300% increase in speed isn't considered better in your opinion
Certainly not in this case. You failed to describe exactly what you meant by saying "best" (assuming that "best" was execution speed), you failed to compare two equivalent solutions to prove your assertion, and you failed to compare the execution speeds correctly. Therefore your premise was subjective, your test was flawed, and your conclusion was biased.

Show me a legitimate 1300% increase in speed and I'll take you more seriously. :icon_rolleyes:

>This is the latest code for the efficiency test, and you will find the results to be quite identical.
Not when taken out of the timing loop. The timing loop should be only for timing, but your "non div + mod calculations" require it for correct behavior. These two snippets are equivalent without the timing loop:

int iX = i % ROW;
int iY = i / ROW;
int iX = 0;
int iY = 0;

for ( int j = 0; j < i; j++ ) {
  if ( ++iX >= ROW ) {
    ++iY;
    iX = 0;
  }
}

That's what I mean by identical results. If you remove the timing loop and run the code with any value of i, and the result is the same. In your code the result is only the same when run with consecutive values of i, which means your method is dependent on the timing loop while the method you …

Narue 5,707 Bad Cop Team Colleague

What language are you doing this in?

Narue 5,707 Bad Cop Team Colleague

>did you open the file i attached?
Seeing as how that was the only way I could have known the required format for the date-time, it's safe to assume that I did. Thanks for asking though.

>Can u help me write the program or modified my code?
Can you read? Because I'm certain I asked you for more detail. If you fail to provide that detail, I'm not going to spend my valuable time rooting through your mass of code trying to find bugs when I have no vested interest in the program.

Narue 5,707 Bad Cop Team Colleague

Amazing! I see you in a completely different light now. It's incredible how showing your code changes you from a leech into someone who deserves help.

>But some function does not working.
Which ones? No offense, but that's a lot of code to troubleshoot with only the "not working" bug report.

>i dun noe how to make the date and time automatically updated
I'm not sure if you're allowed to use it, but strftime is the easiest way to format a date and time. Just call it when you need to update the string and you're solid. Here's an example of how to use it for the current time:

#include <ctime>
#include <iostream>

int main()
{
  char dummy;

  do {
    char buffer[1024];
    time_t now = time ( 0 );

    strftime ( buffer, 1024, "%d-%m-%Y %H:%M:%S", localtime ( &now ) );
    std::cout<< buffer <<'\n';
  } while ( std::cin.get ( dummy ) );
}
Narue 5,707 Bad Cop Team Colleague

You know what I need urgently? Hope for the future in the form of a beginner who actually does his or her own homework without begging for freebies. I actually don't mind giving freebies to people like that because they use the code wisely and for everyone's benefit.

Narue 5,707 Bad Cop Team Colleague

How to do your own work before it becomes urgent? Well, clearly you don't know the answer to that one. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>The due date is tomorrow
And you were given the assignment today, I'm sure. :icon_rolleyes: You seem like yet another boob who screwed around when he should have been working and expects us to provide a free lunch.

You want help? Show us your code. If it looks like you've actually been working on this assignment, you'll appear less like a hopeless leech.

Narue 5,707 Bad Cop Team Colleague

>I am wondering what extra expertise is needed to apply for Job postings
>which says 'Exp in Banking' or 'Exp in Financial industry is a must' ?
Basically, you're expected to have worked in that industry before. You'll be asked to do things that require knowledge of the concepts, terminology, and conventions specific to the industry.

>Can I ,from other domain, apply to such Financial job postings?
You can always apply.

>Will I be able to survive if at all I get selected some how?
Maybe, maybe not, it depends on how quickly you learn. But I wouldn't worry about being selected for a job you aren't qualified to perform.

Narue 5,707 Bad Cop Team Colleague

>Could you please explain to me how to write the
>user defined functions with multiple arguments?
There are three patterns for function parameters. First is a function with no parameters:

void foo();

No parameters is described in code using parentheses where there's nothing between them. Next is a single parameter, which is described in code using a variable declaration between the parentheses:

void foo(int bar);

The third pattern applies to all other numbers or parameters, just keep adding variable declarations and separate them with a comma:

void foo(int bar, double baz, string meep);

>how to make one function to manipulate different data each time it is called?
Pass in different values with each call. Those values will be copied into the variables you declare in the parameter list:

#include <iostream>

int add_all ( int a, int b, int c )
{
  return a + b + c;
}

int main()
{
  std::cout<< add_all ( 0, 1, 2 ) <<'\n';
  std::cout<< add_all ( 3, 4, 5 ) <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>i was wondering how much i should use classes in C++.
As often as you need them, obviously. In my experience, this question is born of ignorance. You don't understand OOP and classes well enough to know when to use them, so you try to turn it into some kind of nonsensical numbers game. It's not that simple, unfortunately.

Just try to figure out the concepts behind a feature and eventually you'll learn when and where it's best used.

>Should i use it as much as possible?
:icon_rolleyes:

Alex Edwards commented: Although someone harsh, I do agree! =) +4
Narue 5,707 Bad Cop Team Colleague

>I'm trying to prove to my teacher that Div and Mod isn't always the best way to solve things.
I find it humorous that you seem to think "fastest" and "best" are synonymous.

>You're all welcome to show your instructors this =)
Oh, I will indeed. It's a very amusing test, seeing as how an accurate comparison of a feature and it's alternative should produce the same results for both when hoisted out of the timing loop. I'm curious how you think that this:

iX = i % ROW;
iY = i / ROW;

Has identical results to this:

iX++;
if (iX >= ROW)
{
  iY++;
  iX = 0;
}
Narue 5,707 Bad Cop Team Colleague

>How would I generate a csv file
The first thing that comes to mind is a sparse matrix to store the coordinates and value. Then when you iterate through the matrix, you can fill the gaps with empty fields and blank lines as appropriate, and really all you need to search for is the maximum number of fields:

int max_fields = 0;

// Find the largest column value
for ( int i = 0; i < matrix.size(); i++ ) {
  for ( int j = 0; j < matrix[i].size(); j++ ) {
    if ( matrix[i][j].column > max_fields )
      max_fields = matrix[i][j].column;
  }
}

int row = 0;

// Write out the CSV format
for ( int i = 0; i < matrix.size(); i++ ) {
  while ( row != matrix[i][0].row ) {
    new_csv_row();
    ++row;
  }

  int k = 0;

  for ( int j = 0; j <= max_fields; j++ ) {
    if ( k < matrix[i].size() && j == matrix[i][k].column )
      put_csv_field ( matrix[i][j].value );
    else
      put_csv_field ( "" );
  }

  new_csv_row();
}

Simple and effective.

Narue 5,707 Bad Cop Team Colleague

>#include <iomanip> // what is this library used for
The <iomanip> header essentially declares stream manipulators that take an argument. This is as opposed to those stream manipulators that don't take a special argument and are declared in the <ios> header.

The code you posted is actually incorrect in that it includes <iomanip>, but uses manipulators that are declared in <ios> (std::oct, std::dec, and std::hex). However, due to the common inclusion of <ios> by <iostream>, it works as intended. I'd recommend that you drop <iomanip> and include <ios> directly for maximum portability. I'd also recommend explicitly qualifying your standard names with std:: and not abusing the using directive:

#include <iostream>
#include <ios>
#include <string>
#include <bitset>

int main()
{
  std::cout << "Enter a binary number: ";

  std::string bin;

  if (getline(std::cin, bin)) {
    std::bitset<32> bits(bin);
    std::cout <<"Octal  ";
    std::cout << std::oct << bits.to_ulong() << '\n'; 
    std::cout <<"Hex   ";
    std::cout << std::hex << bits.to_ulong() << '\n';
    std::cout <<"dec   ";
    std::cout << std::dec << bits.to_ulong() << '\n';
  }

  return 0;
}

>//what does the bits.to_ulong() part do or what is it tied to .
to_ulong takes the bit pattern stored in bits and copies it in an unsigned long value. The result is that the bit pattern "11011" will produce 27 when you call to_ulong() and print the value as a decimal number.

Narue 5,707 Bad Cop Team Colleague

Post your code.

Narue 5,707 Bad Cop Team Colleague

I'm not sure what you mean, but I'd guess that you don't know how to signal end-of-file from the command line, so the loop never ends. Hold down the ctrl key and press z (ctrl+z) if you're on Windows and d (ctrl+d) if you're on Unix or Linux.

Narue 5,707 Bad Cop Team Colleague

>I believe it wants us to write a program that we input a number, and we
>have to be able to output how many digits are output to a particular base.
That's trivial too. numdigits as it stands is specific to decimal only because it uses literal 10's in the loop condition and division step.

Narue 5,707 Bad Cop Team Colleague

>It's because I'm going to generate poisson random deviates for parallel-programming
>and I need it to be seed-less to ensure concurrent execution.
No, you just need the seeding mechanism to work properly for your concurrent processes. However, you didn't specify what "work properly" means for you. Do you want each process to have the same sequence or do you want all generated numbers to be distributed randomly across all processes? The answer to that question determines what you should be looking for.

If you want each process to have the same sequence, then you only have an issue with multi-threading where all threads share the same resources (which includes the global seed if you're using something like C++'s rand).

The first way to deal with creating the same sequence is to re-seed the generator for every thread (or every process) if the generator is thread-aware. If it isn't thread-aware, the easiest solution in my opinion is to write a good generator that has the seed passed in as part of the interface:

#define N 624
#define M 397
#define A 0x9908b0dfUL
#define U 0x80000000UL
#define L 0x7fffffffUL

struct twister_state {
  unsigned long x[N];
  int next;
};

twister_state twister_seed ( unsigned long s )
{
  twister_state state;

  state.x[0] = s & 0xffffffffUL;

  for ( int i = 1; i < N; i++ ) {
    state.x[i] = ( 1812433253UL 
      * ( state.x[i - 1] ^ ( state.x[i - 1] >> 30 ) ) + i );
    state.x[i] …
Narue 5,707 Bad Cop Team Colleague

>what re the certifications available for networking? how to begin and the highest?
I'll be blunt. If you're looking for the easiest field, quit IT now and focus on something better suited to your interests and abilities. Not only is your attitude prone to failure, you'll also end up being a piss poor professional who does piss poor work "just to get a paycheck".

>would u also suggest networkin?
I didn't suggest networking. You asked which of those listed was easiest, and I offered my opinion on that question. If you want my opinion of which you should choose, then based on what I've seen of you, I'd say none of the above.

Narue 5,707 Bad Cop Team Colleague

>what facet of the IT world would you advise a newbie like me to venture in
The one you find most interesting. Or if you have no preference, get a taste of them all until you do.

>or which do you think is easiest?
Of those listed I think networking is easiest, but I also think it's the most boring.

Narue 5,707 Bad Cop Team Colleague

>Is C++ going to barf on that
Possibly. It depends on whether A contains data members and if having multiple copies of the A subobject within a C object would cause problems in your code. Virtual inheritance was introduced to alleviate these kinds of problems.

Narue 5,707 Bad Cop Team Colleague

>How else would I go about doing
Use a static member function, or provide a non-member helper that does what you want.

Narue 5,707 Bad Cop Team Colleague

>I want the discussion to be related to my requirements, please.
You didn't specify any requirements that can't be achieved with either language. Pick the one you're most comfortable with.