gerard4143 371 Nearly a Posting Maven

What's your copy constructor look like?

gerard4143 371 Nearly a Posting Maven

I would drop all the references to pointers(* &) and just use references like the above posting.

gerard4143 371 Nearly a Posting Maven

Why are you using a reference to a pointer in your equals operator?

ThuggyWuggy commented: Solved problem, thanks +1
gerard4143 371 Nearly a Posting Maven

Try the escape sequence \" e.g.

std::cout << "this is a quote \"" << std::endl;
gerard4143 371 Nearly a Posting Maven

If the memory manager can fulfill the malloc request it will return a memory pointer to the allocated memory...if it fails it returns NULL.

If malloc returns a pointer other than NULL then you have your requested memory.

gerard4143 371 Nearly a Posting Maven

The problem is line 13

_matrix.GetM(i, k)

The vector container has no method called GetM().

gerard4143 371 Nearly a Posting Maven

Pointers that are not set to NULL or a valid memory address are said to be wild pointers, they may be pointing at anything so are very dangerous.

The general rule is - Set a pointer to a valid memory address or set it to NULL...Always keep your pointers in a known state.

gerard4143 371 Nearly a Posting Maven

I see. How exactly do I sum up all the scores for average?

Try something like below...Note array elements start at zero not 1.

#include <iostream>

#define ARR_SIZE 5

int main()
{
  int totnum[ARR_SIZE];
  signed long sum = 0;
  
  for (size_t i = 0; i < ARR_SIZE; ++i)
  {
	std::cout << "Enter element [" << i << "]->";//note array elements start at 0
	std::cin >> totnum[i];
  }

  for (size_t i = 0; i < ARR_SIZE; ++i)
  {
	std::cout << "Element [" << i << "]->" << totnum[i] << std::endl;
	sum += totnum[i];
  }
  
  std::cout << "sum->" << sum << std::endl;
  return 0;
}
gerard4143 371 Nearly a Posting Maven

And array is just a contiguous block of memory. Its doesn't support the division operator.

gerard4143 371 Nearly a Posting Maven

All I can tell you is, get a good book on the subject.

Here's a website, check some of the titles.

http://www.cs.purdue.edu/homes/dec/netbooks.html

especially - Internetworking With TCP/IP Volume III: Client-Server Programming and Applications, Linux/POSIX Socket Version (with D. Stevens)

gerard4143 371 Nearly a Posting Maven

I know the GNU g++ complier has limited support with the -std=gnu++0x switch.

gerard4143 371 Nearly a Posting Maven

Maybe if you tried

if ((scode == "r") || (scode == "R"))
gerard4143 371 Nearly a Posting Maven

I see where your calling callInitialize() but not where your calling Initialize().

gerard4143 371 Nearly a Posting Maven

How and what are you calling Initialize (List *L) with.

Note: You have this

L->items[i].name[MAXNAMESIZE - 1] = '\0';

Shouldn't it be

L->items[i].name[strlen(initialize)] = '\0';

...After checking the docs I found strncpy pads the destination with '\0' so my point is null void.

gerard4143 371 Nearly a Posting Maven

I can't believe you compiler didn't warn you about this line..

char test = "I like you";

Is this what your trying to do?

#include <stdio.h>

#define ARR_SIZE 3

struct mys
{
  char * my_arr[ARR_SIZE];
};

int main()
{
  size_t i = 0;
  struct mys thes;
  
  char * test1 = "I like you";
  char * test2 = "I like you...not";
  char * test3 = "Hello, world!";
  
  thes.my_arr[0] = test1;
  thes.my_arr[1] = test2;
  thes.my_arr[2] = test3;
  
  for (i = 0; i < ARR_SIZE; ++i)
	fprintf(stdout, "ans->%s\n", thes.my_arr[i]);
  return 0;
}
gerard4143 371 Nearly a Posting Maven

How are you calling - void populate_bricks(sprites &game_data)?

gerard4143 371 Nearly a Posting Maven

PS How would I setup virtual memory in linux?
Muffins

Your in luck, Linux already comes with virtual memory set up.

gerard4143 371 Nearly a Posting Maven

Do you mean something like below?

#include <iostream>

class A
{
public:
  virtual void display_it() const { std::cout << "class A" << std::endl; }
protected:
	int x;
};
class B : public A
{
public:
  void display_it() const { std::cout << "class B" << std::endl; }
	int y, z;
};

class C
{
public:
	C(bool derivedClass)
	{
		if (derivedClass)
		{
			pAB = new B;
		}
		else
		{
			pAB = new A;
		}
	}
	
	void whoami() const { pAB->display_it(); }
	
	A* pAB;
	// other members
};

int main(int argc, char**argv)
{
  C one(true);
  C two(false);
  
  one.whoami();//class B
  two.whoami();//class A
  
  return 0;
}
Jsplinter commented: Thank you. Well explained. +3
gerard4143 371 Nearly a Posting Maven

Correction: class B is derived from class A, so creating an object of type B will automatically create an internal object of A. Object of type C contains a pointer to object of type A

Yes, thank-you for the correction.

gerard4143 371 Nearly a Posting Maven

Class C is derived from class A, so creating an object of type C will automatically create an internal object of A. Object of type C contains an object of type A

gerard4143 371 Nearly a Posting Maven

A simple method would be

char aChar;
char nline;
printf("Please enter a character: ");
scanf("%c%c",&aChar, &nline);
gerard4143 371 Nearly a Posting Maven

aahhh, i see '\n' has an ascii value of 10.
so when an input is given say 'e', '\n' tags along.
now to find a way to either remove it or to consume it with the user input??

Well almost. '\n' doesn't tag along, its entered by the user to indicate he's done inputing values..

Your example - When a user enters a value 'e' he/she really enters/types 'e' and then hits/types the enter key which is the '\n'.

gerard4143 371 Nearly a Posting Maven

Try running this code

#include <stdio.h>
 
int main()
{
    char aChar;
    printf("Please enter a character: ");
    scanf("%c",&aChar);
 
    while (aChar!='x')
    {
        printf("The Letter is %c or the integer is->%d\n", aChar, aChar);
 
        printf("Please Enter another character: ");
        scanf("%c", &aChar);
    }
    return 0;
 
}

Can you figure out what's going on? Hint 10 is new line.

gerard4143 371 Nearly a Posting Maven

If your not using the unsafe keyword, I doubt you have a memory leak or a memory leak that you cam fix(i.e. It may be a problem with the database api).

Note: I wouldn't base memory leaks solely on the task manager's memory indicator since C#'s garage collector isn't consistent in its duties.

gerard4143 371 Nearly a Posting Maven

Not sure what your trying to accomplish in your code but you could investigate the rename function that resides in cstdio or stdio.h.

int rename(const char *oldpath, const char *newpath);
gerard4143 371 Nearly a Posting Maven

Try creating a == operator, something like below

bool operator ==(const Sample & s) { return a == s.a; }
gerard4143 371 Nearly a Posting Maven

I herd that some C++ compilers can use asembly languige in there programs along side C++, How would I do This? And is there any way to use a compiler as an assembler? <<two questions.

How do you integrate assembly into C++? Generally most compilers provide inline assembly as an extension to the C++ compiler.

How is this accomplished? Most vendors provide a keyword asm or __asm or __asm__ which you can follow with assembly instructions...Here's a link.

http://msdn.microsoft.com/en-us/library/45yd4tzz%28v=vs.71%29.aspx

Is there a way to use the C++ compiler as an assembler? Yes, all C/C++ compilers I used assembled the code.

gerard4143 371 Nearly a Posting Maven

Think of a void pointer as a dimensionless pointer. It has to be cast to a data type with a dimension before it can be referenced...Like below.

int x = 5;
void *vptr = (void*)&x;
int *iptr = (int*)vptr;
fprintf(stdout, "*iptr->%d\n", *iptr);
gerard4143 371 Nearly a Posting Maven

Just compiled and ran your code using gcc, it worked fine.

gerard4143 371 Nearly a Posting Maven

@cse.avinash
actually i didnt get the meaning of *((char*)iPtr)..what does it mean??

It means cast iPtr to a character pointer with (char*) and then dereference it.

*((char*)iPtr) getting the value it points to.

gerard4143 371 Nearly a Posting Maven

Maybe it would help to look at what 258 is in binary

00000001 00000010

Which is 1 and 2.

gerard4143 371 Nearly a Posting Maven

Not sure why your handling your pointer that way? Try writing your program like below:

#include <stdio.h>
#include <stdlib.h>

#define ELEM_POS 2

int main(int argc, char** argv)
{
    int x[] = {1, 2, 3, 4};
    char *p = (char*)x;

    fprintf(stdout, "p->%d\n", *(int*)p);

    p = (char*)(p + sizeof(int) * ELEM_POS);

    fprintf(stdout, "p->%d\n", *(int*)p);
    return (EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

You may be wondering why two + operators are required? Try reading this link, it may clear up some of your confusion.

http://www.bogotobogo.com/cplusplus/this_pointer.html

I should clarify that Mike 2k's solution doesn't require this explanation because both + operators are defined outside of the class Number but if you had a class something like below:

#include <iostream>

class Number
{

public:

    Number():itsvalue(0) {}
    Number(int val):itsvalue(val) {}

    Number operator +(const Number & a) const { return itsvalue + a.itsvalue; }

    int getitsvalue() const { return itsvalue; }

private:

    int itsvalue;

};

Number operator +(const int val, const Number & n) { return val + n.getitsvalue(); }

std::ostream& operator <<(std::ostream & out, const Number & n)
{
    return out << n.getitsvalue();
}

int main(int argc, char** argv)
{
    int x = 123;
    Number my_n(789);

    std::cout << x + my_n << std::endl;
    std::cout << my_n + x << std::endl;
    return 0;
}

Then the explanation does make sense.

gerard4143 371 Nearly a Posting Maven

Try something like below

#include <stdio.h>
#include <stdlib.h>

unsigned long *lptr = NULL;

int main()
{
  lptr = (unsigned long*)malloc(sizeof(unsigned long));
  
  /*check if allocation failed*/
  
  __asm__ 	(
				"movq	%0, %%rax\n\t"
				"movq	$6, (%%rax)\n\t"
				:"=m"(lptr)
			);
			
  fprintf(stdout, "ans->%lu\n", *lptr);
  return 0;
}
wildplace commented: =D great helpl +2
gerard4143 371 Nearly a Posting Maven

For this to work, you'll have to inspect each character from the stream using the isdigit() function.

gerard4143 371 Nearly a Posting Maven

The operating system will use the next lowest file descriptor for that application. It really makes sense if you think about it. Would you expect the operating system to return a random number?

The third value is used if open creates a new file, its the umask value that's applied to the newly created file.

vedro-compota commented: +++++++++++ +1
gerard4143 371 Nearly a Posting Maven

Try compiling this program

testp.c

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char**argv)
{
  char ch;
  FILE *fd = NULL;
  
  if ( argc != 2 )
  {
	fputs("usage error - a.out <Filename>\n", stderr);
	exit(EXIT_FAILURE);
  }
  
  if (!(fd = fopen(argv[1], "r")))
  {
	fprintf(stdout, "Could not open %s\n", argv[1]);
	exit(EXIT_FAILURE);
  }
  
  while (fread(&ch, sizeof(char), 1, fd))
  {
	fprintf(stdout, "%p ", (void*)ch);
  }
  
  fclose(fd);
  return 0;
}

Now pass a file name as a command line argument..It should display the binary(hex values) contents of the file.

gerard4143 371 Nearly a Posting Maven

Really, why would you want to? You know that some of the binary characters have no ascii representation, hence can't be displayed. It would be better to display each binary value in hex, thus displaying each and everyone of them.

gerard4143 371 Nearly a Posting Maven

I just tried that but I didnt help. But am I right assuming that it->first is a const int due to the iterator being constant and you wanted to match parameters?

I was mistaken, because the function

std::vector<passenger*>& passenger_queue::passengers_at_floor(int floor_)

makes a copy of the const data member first, its allowed.

gerard4143 371 Nearly a Posting Maven

It could be this function

std::vector<passenger*>& passenger_queue::passengers_at_floor(int floor_)

Try changing it to

std::vector<passenger*>& passenger_queue::passengers_at_floor(const int floor_)
gerard4143 371 Nearly a Posting Maven

Well you could find out the hex value of 2584 and then place the appropriate values in the correct array elements or you could extend your array to five elements and create a c-string and use the function atoi() like below.

#include <stdio.h>
#include <stdlib.h>

int main()
{
  char ch[5] = {'2','5','8','4','\0'};
  int ans = atoi(ch);
  
  fprintf(stdout, "ans->%d\n", ans);
  return 0;
}
gerard4143 371 Nearly a Posting Maven

Try looking at the code below.

#include <stdio.h>
#include <stdlib.h>

void myfunction(int **array1, int **array2)
{
  int i = 0, j = 0;
  
  for (i = 0; i < 4; ++i)
  {
	for (j = 0; j < 4; ++j)
	{
	  fprintf(stdout, "ans->%d\n", array1[i][j]);
	  fprintf(stdout, "ans->%d\n", array2[i][j]);
	}
  }
  
}

int main(int argc, char**argv)
{
  int i = 0, j = 0;
  int **myarray1;
  int **myarray2;
  
  myarray1 = (int**)malloc(4 * sizeof(int*));
  myarray2 = (int**)malloc(4 * sizeof(int*));
  
  for (i = 0; i < 4; +++i)
	myarray1[i] = (int*)malloc(4 * sizeof(int));
  
  for (i = 0; i < 4; +++i)
	myarray2[i] = (int*)malloc(4 * sizeof(int));
  
  for (i = 0; i < 4; ++i)
  {
	for (j = 0; j < 4; ++j)
	{
	  myarray1[i][j] = i + j;
	  myarray2[i][j] = i + j;
	}
  }
 
  myfunction(myarray1, myarray2);
  /*free memory here*/
  return 0;
}
gerard4143 371 Nearly a Posting Maven

Try creating your function like so

void myfunction(int array1[][4], int array2[][4])

And calling it like so

myfunction(myarray1, myarray2);
gerard4143 371 Nearly a Posting Maven

Your not guaranteed how the arguments in printf are evaluated, left to right, right to left..It depends on the C compiler your using!!!!!!!!!!!!!!!!!!!!!(many ! so the reply is urgent).

gerard4143 371 Nearly a Posting Maven

Try it with 2 char arrays that you declare one right after the other, which don't have to adjoin in memory but with such a small program they often do, then write more into the second one than it can hold. If you print it out it's clobbered the first one.

I was assumed, he was only taking seven characters from the stream and placing them in the array and the terminating it(the array) with '\0'. In this instance, the remaining characters would be in the stream.

In the scenario your describing, you would indeed have a buffer overflow and possible data corruption.

gerard4143 371 Nearly a Posting Maven

If someone inputted a string that was 15 letters long, would the leftover characters after the null terminator be discarded? or would they remian in the input stream?

And on one last note: is there a way to expand my character array size once it's defined?

Your first question. Yes the characters remain in the stream.

Your second question. No you can't change the size of a static array but you can create a dynamic array with new and that array can be changed(or recreated).

gerard4143 371 Nearly a Posting Maven

I omitted the cin portion, is that what you mean?

Yeah I guess you could do it that way... something like below.

#include <iostream>

#define ARR_SIZE 8

int main()
{
  int i = 0;
  char input[ARR_SIZE];
  
  while(input[i] = std::cin.get() , input[i]  != '\n' && i < (ARR_SIZE - 1))
  { 
	i++;
  }
  
  input[i] = '\0';

  std::cout<<input<< std::endl;;
  return 0;
}
gerard4143 371 Nearly a Posting Maven

input[8] is not the last member of your array, input[7] is.

When you declare the array you put the size, when you use the array, you put the index.

After taking in the input, you could say

if(input[7] != '\0')
   input[7] = '\0'

What I think you were doing is trying to march down the string, which you can do by

int i = 0;
while(input[i] != '\0')
{ 
   cout<<input[i]<<" ";
   i++;
}
(it could be a for loop too, I was just using while because you did)

Shouldn't your code initialize input to a value that is not '\0' first.

gerard4143 371 Nearly a Posting Maven

I would look up the functionality of getline().

http://www.cplusplus.com/reference/iostream/istream/getline/

gerard4143 371 Nearly a Posting Maven

You have a number of questionable things in that function.

float calcActualAmount(float amountP, int nrChildrenP)
{

  float leftToSpend;
  if (calcAllowedPerChild(nrChildrenP) > 180)
	amountP = 180;
  else if (calcAllowedPerChild(nrChildrenP) < 180)
	leftToSpend = calcAllowedPerChild(nrChildrenP) - 100;
  
  do
  {
	for (int i = 1; i <= 5; i++)
	{
	  switch (i)
	  {
	  case 1: leftToSpend -= TOOTHBRUSH;
	  break;
	  case 2: leftToSpend -= HIGHLIGHTERS;
	  break;
	  case 3: leftToSpend -= CRAYONS;
	  break;
	  case 4: leftToSpend -= NOTEBOOK;
	  break;
	  case 5: leftToSpend -= PEN;
	  break;

	  amountP = calcAllowedPerChild(nrChildrenP) - leftToSpend;/*why are you calling this agin?*/

	  }
	}

  return amountP;
  }
  while (leftToSpend == 0);/*whats the purpose of this?*/
}