gerard4143 371 Nearly a Posting Maven

Are you opening this port as a privileged user?

gerard4143 371 Nearly a Posting Maven

Until you show some effort and post some code with specific questions, nobodies going to help you.

gerard4143 371 Nearly a Posting Maven

I actually found the answer here at Daniweb...It turns out that the C++ standard won't allow the std::pair and copy to work together if the elements of std::pair are both or one each of built in types or std::types.

http://www.daniweb.com/software-development/cpp/threads/154030

So after many months on the back burner, Daniweb comes to the rescue.

#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <iterator>

struct mys
{
    unsigned long x;
};

std::ostream& operator <<(std::ostream & out, const std::pair<const std::string, struct mys> & p)
{
    return out << p.first << " " << p.second.x;
}

int main(int argc, char** argv)
{
    std::map<std::string, struct mys> the_words;

    the_words["G4143"].x += 1;
    the_words["G4143"].x += 1;
    the_words["was"].x += 1;
    the_words["here"].x += 1;
    
    copy(the_words.begin(), the_words.end(), std::ostream_iterator< const std::pair<const std::string, struct mys> >(std::cout, " "));

    std::endl(std::cout);
    
    return 0;
}
gerard4143 371 Nearly a Posting Maven

Yeah, I need a million cdn dollars maybe we can work out a deal.

gerard4143 371 Nearly a Posting Maven

You might want to put 'system("pause")' before return 0.

gerard4143 371 Nearly a Posting Maven

Yes, I'm surprised your compiler allowed it. The assignment operator must return a reference to the object.

gerard4143 371 Nearly a Posting Maven

try

std::vector<Rab> items;
jackmaverick1 commented: Perfect +3
gerard4143 371 Nearly a Posting Maven

try

#include <cstdio>

int ca;
ca = fgetc(stdin);
gerard4143 371 Nearly a Posting Maven

Where is your arguments defined? frequency, expected, intRepeats?

displayResult(frequency, expected, intRepeats);
gerard4143 371 Nearly a Posting Maven

I tried this and my compiler didn't complain.

#include <iostream>
#include <vector>
#include <string>

using namespace std;

class GameUnit {
  public:
    string GetName()  {return Name;}
  protected:
    string Name;
};


class Player {
  public:
    void ListUnits();
  protected:
    vector<GameUnit*> MyUnits;
};

void Player::ListUnits() {
  for(unsigned int i=0; i<MyUnits.size(); i++) {
    cout<<MyUnits[i]->GetName()<<"\n";
  }
}

int main()
{
  return 0;
}
gerard4143 371 Nearly a Posting Maven

So whats' the problem?

gerard4143 371 Nearly a Posting Maven
#include<stdio.h>

	struct rec
	{
    		int i;
    		float PI;
    		char A;
	};

	int main()
	{
		struct rec *ptr_one;
		ptr_one =(struct rec *) malloc (sizeof(struct rec));

		ptr_one->i = 10;
    		ptr_one->PI = 3.14;
    		ptr_one->A = 'a';

    		printf("First value: %d\n", ptr_one->i);
    		printf("Second value: %f\n", ptr_one->PI);
    		printf("Third value: %c\n", ptr_one->A);

    		free(ptr_one);

   		return 0;
	}

what is the use of -> in c.can we use it in all programming languages

Can you use it in all programming languages? Only if the programming language recognizes -> as a valid operator.

gerard4143 371 Nearly a Posting Maven

I am pretty sure I can also achieve the same now, but not unless I can pass two.exe a pid and a pointer.
(

Sounds like your accessing the parent or client address space via its pid and a pointer which sounds like your processes may not be sharing an address space.

Note: I have programmed on Windows system infrequently, so I'm ignorant of its functionality.

gerard4143 371 Nearly a Posting Maven

I was under the impression that a child process shares memory space.

I pass an int pointer to one app at runtime via command line and the second app modifies it. Since both apps know the address they can share the variable between them.

At least that is how I thought it to work, I have certainly done this in another scripting language, passing a whole array of pointers.

No a child process(at least a child process in Linux) has its own address space so passing pointers from its parent will be meaningless.

Maybe you could pass along some specifics of what your trying to do.

gerard4143 371 Nearly a Posting Maven

It doesn't make sense to pass memory pointers between address spaces.

gerard4143 371 Nearly a Posting Maven

Look up arbitrary precision arithmetic libraries like

http://gmplib.org/

gerard4143 371 Nearly a Posting Maven

start_routine is the entrance point of the thread create with pthread_create.

gerard4143 371 Nearly a Posting Maven

When I try to this, it will only print the first character of the particle name...

That's because your scanning a character

sscanf(line.c_str(), "%c %c %f %f %f %f %f", &(current_step.m_plus), &(current_step.m_particle), &(current_step.m_energy_sec), &(current_step.m_xpos_sec), &(current_step.m_ypos_sec), &(current_step.m_zpos_sec));

In you format string the second specifier is %c which is character. Try using %s for the second specifier.

sscanf(line.c_str(), "%c %s %f %f %f %f %f", &(current_step.m_plus), current_step.m_particle, &(current_step.m_energy_sec), &(current_step.m_xpos_sec), &(current_step.m_ypos_sec), &(current_step.m_zpos_sec));

Just noticed

class dm_Step
{
public:
	char m_plus;
	char m_particle;//you'll have to change this to a character array like char m_particle[20]; 
	float m_energy_sec;
	float m_xpos_sec;
	float m_ypos_sec;
	float m_zpos_sec;
};
gerard4143 371 Nearly a Posting Maven

And the last one

char * p2 = "Some string";
printf("Unknown (with asterisk): %d\n", *p2);

Unknown (with asterisk): 83

dereferncing a character pointer returns the character pointed to which is 'S' and the numeric(ascii) value of 'S' is 83.

gerard4143 371 Nearly a Posting Maven

I would say that this is the value of the address held by p3

Unknown (without asterisk): 4210883
gerard4143 371 Nearly a Posting Maven

Sure:

size->4
size->4
size->0022FF4C
size->2293580

~G

I just wanted to make sure you weren't truncating anything..

Now lets look at

int * p3 = "47352";//assign to pointer p3, the pointer that points to "47352"

Unknown (with asterisk): 892548916

*p3 produces 892548916

now 892548916 has a hex value of 0x35333734 which has ascii values

0x35 = '5'
0x33 = '3'
0x37 = '7'
0x34 = '4'

notice that p3 points to "47352" which is an int pointer and int are four bytes on your system so your getting the first four characters of the string "47352".

Graphix commented: Thanks for the help +6
gerard4143 371 Nearly a Posting Maven

Could you post the results of running this code.

#include <stdio.h>

int main()
{
  int x;
  fprintf(stdout, "size->%lu\n", sizeof(void*));
  fprintf(stdout, "size->%lu\n", sizeof(int));
  
 
  fprintf(stdout, "size->%p\n", (void*)&x);
  fprintf(stdout, "size->%d\n", (int)&x);

  return 0;
}
gerard4143 371 Nearly a Posting Maven

So what's the problem? Please give details.

gerard4143 371 Nearly a Posting Maven

First off your missing two includes

#include <stdlib.h>
#include <string.h>

Also this function

void add(char *firstName, char *lastName, int *exam) {
     struct node *newnode = malloc(sizeof(struct node));

     newnode->firstName = firstName;//must use strcpy(newnode->firstName, firstname)
     newnode->lastName = lastName;//must use strcpy(newnode->lastName, lastName)
     newnode->exam = exam;//actually not sure what your doing here
     newnode ->next = NULL;
     if (head == NULL) {
          head = newnode;
     }
     else {
          struct node *cur = head;
          while (cur->next != NULL) {
              cur = cur->next;
          }
          cur->next = newnode;
     }
}
gerard4143 371 Nearly a Posting Maven

The .exe file doesn't executes effectively in other computers which doesn't have TC installed, although it works fine graphically in my PC and it's because i've TC installed.

Keeping it short and simple "Is there any way to embedded the standard obj and lib files into the the exe file so that it can independently run on any computer which doesn't have a TC installed"

Regards

You might be able to statically link them into one big exe. It really depends on TC's compiler and the libraries available.

gerard4143 371 Nearly a Posting Maven

Maybe you could elaborate on 'this code doesn't execute'.

gerard4143 371 Nearly a Posting Maven

Yup that's it. You also have this at the bottom of your code.

if (PlayerChoice == Paper)
{
  switch (random)
  {
	case Rock: outcome = Win; break;
	case Paper: outcome = Draw; break;
	case Scissors: outcome = Lose; break;
  }
}

if (PlayerChoice == Scissors)
{
  switch (random)
  {
	case Rock: outcome = Lose; break;
	case Paper: outcome = Win; break;
	case Scissors: outcome = Draw; break;
  }
}

switch (outcome)
{
  case Win: cout << "Player Wins!\n\n"; break;
  case Lose: cout << "Player Loses!\n\n"; break;
  case Draw: cout << "Draw\n\n"; break;
}

It really should belong to a function.

Note where your function ends.

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

enum Choice { Rock, Paper , Scissors }; // Rock=0, Paper=1, Scissors=2
enum Decision { Draw, Win, Lose }; // Draw=0, Win=1, Lose=2

char DoMenu();
void CheckWinner (int PlayerChoice);

int main()
{
  // Use computers random choice generator
  srand(time(0));

  // declare variables
  char choice;

  do
  {
	choice = DoMenu();

	switch (choice)
	{
	  case 'R': // fall through
	  case 'r': cout << "\nPlayer: Rock\n"; CheckWinner(Rock); break;
	  case 'P': // fall through
	  case 'p': cout << "\nPlayer: Paper\n"; CheckWinner(Paper); break;
	  case 'S': // fall through
	  case 's': cout << "\nPlayer: Scissors\n"; CheckWinner(Scissors); break;
	  default : cout << "\n";
	}

  } while ((choice != 'Q') && (choice != 'q'));


  // end program
  return 0;
}

char DoMenu()
{
  char MenuChoice;
  cout << "(R)ock\n";
  cout << "(P)aper\n";
  cout << "(S)cissors\n";
  cout << "----------\n";
  cout << "Choice: "; …
gerard4143 371 Nearly a Posting Maven

Number one, your missing the includes

#include <cstdlib>

What looks wrong here?

if (PlayerChoice == Paper);

Please use code tags and proper formating when posting code.

gerard4143 371 Nearly a Posting Maven

If your getting syntax errors and stuff. Please post them.

gerard4143 371 Nearly a Posting Maven

So for the case solution you showed. When i put in something other thna a number it gives me back that item. for example if i put in the letter c it outputs c instead of -1

int toNumber(char c)
{
  switch (c)
  {
	case '0':
	  return 0;
	case '1':
	  return 1;
	case '2':
	  return 2;
	case '3':
	  return 3;
	case '4':
	  return 4;
	case '5':
	  return 5;
	case '6':
	  return 6;
	case '7':
	  return 7;
	case '8':
	  return 8;
	case '9':
	  return 9;
	default:
	  return -1;
  }
  return 0;

}

Really I don't see how that's possible?

You have a number of problems with this code.

do
  {
    cout  <<  endl  <<  "Enter a character (q to quit): ";
    cin  >>  ch;
 if  ( toNumber( ch ) )
      cout  <<  ch <<  endl;
} while( ch != 'q' );

toNumber() returns a number 0 - 9 and -1.

0 is false and everything else is true..How do you think that works in your if statement?

Also your displaying the character passed to toNumber() and your surprised its displayed!

gerard4143 371 Nearly a Posting Maven

What I would do is create my own rand function say my_rand()

int my_rand(unsigned int max, unsigned int min)
{
int ans;
/*do something here to generate answer*/
/*hint: ans = (rand () % (1 + max - min) + min )*/
return ans;
}
gerard4143 371 Nearly a Posting Maven

Do you mean your trying to create a new function that generates pseudo-random integers? I hope your not trying to pass something to rand().

int rand(void);
gerard4143 371 Nearly a Posting Maven

Im guessing a blank character. Something like char c = " ". But I tried this and it wouldnt work.

Well " " is not a blank character, ' ' is a blank character.

If your trying to mimic the C function isspace() then maybe you should consider these as spaces as well.

From the man pages

isspace()
              checks  for  white-space characters.  In the "C" and "POSIX" locales,
              these are: space, form-feed ('\f'), newline ('\n'),  carriage  return
              ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
gerard4143 371 Nearly a Posting Maven

For your first function try something like below:

int toNumber(char c)
{
  switch (c)
  {
	case '0':
	  return 0;
	case '1':
	  return 1;
	case '2':
	  return 2;
	case '3':
	  return 3;
	case '4':
	  return 4;
	case '5':
	  return 5;
	case '6':
	  return 6;
	case '7':
	  return 7;
	case '8':
	  return 8;
	case '9':
	  return 9;
	default:
	  return -1;
  }
  return 0;
}

For your second function, what constitutes a space?

gerard4143 371 Nearly a Posting Maven

Try something like this

#include <iostream>

class test {
    public:
        int* num;
    };

int main() {
    test *d = new test;
    d->num = new int;
    *(d->num) = 3;
  std::cout << *(d->num);
}
ProgrammingGeek commented: thanks +1
gerard4143 371 Nearly a Posting Maven

I'm not sure what you mean by 'How does it actually work?'.

gerard4143 371 Nearly a Posting Maven

Sounds like your using unsigned characters for one and signed characters for the other.

gerard4143 371 Nearly a Posting Maven

Try looking up the functions fork() and execlp().

gerard4143 371 Nearly a Posting Maven
string getPrintStr(int colorEnum)
{
switch (colorEnum)
  {
	case red:
	  return "red";
	case green:
	  return "green";
	case blue:
	  return "blue";
  }
return "unknown color";
}

Your function should really be.

string getPrintStr(const colour & colorEnum)
{
switch (colorEnum)
  {
	case red:
	  return "red";
	case green:
	  return "green";
	case blue:
	  return "blue";
  }
return "unknown color";
}
gerard4143 371 Nearly a Posting Maven

That's a new one 'enum operator'. What's that?

Do you mean something like below?

#include <iostream>

enum colour {red, green, blue};

std::ostream& operator <<(std::ostream & out, const colour & c)
{
  switch (c)
  {
	case red:
	  return out << "red";
	case green:
	  return out << "green";
	case blue:
	  return out << "blue";
  }
  return out;
}

int main()
{	
	
	colour favourite;
	favourite = green;

	std::cout << favourite << std::endl;

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Well its really simple

struct student
{
std::string name;
double midterm, final;
std::vector<double> assignments;
};

int main()
{
struct student a_student;
a_student.assignments.push_back(value);
return 0;
}
gerard4143 371 Nearly a Posting Maven

It works fine for regular formatted files such as WORD-documents and text files, but with movies it stops after about 705 bytes, although the file is 42MB. I think it's because there is a EOF character in the middle of the file which breaks up the while loop. Does anyone know how to solve this?
~G

EOF is not stored with the file but is return by the operating system when its encountered.

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1048865140&id=1043284351

gerard4143 371 Nearly a Posting Maven

I'm having problems figuring out what you mean.

gerard4143 371 Nearly a Posting Maven

OMg omg! I found the solution... I should use g++ instead of gcc.. hehe Thanks anyway :)

Yeah that would do it. Did it myself from time to time.

gerard4143 371 Nearly a Posting Maven

I tried looking at your program but had some problems

#include<stdio.h>
#define SIZE 100

int getline(char line[], int lim)
{
  int c,i;

  for( i = 0; i < (lim - 1) && (c=getchar()) != '\0'; ++i)/*characters are surrouned by single quotes*/
	line[i] = c;
  
  if(c == '\n')/*characters are surrouned by single quotes*/
  {
	line[i]=c;
	++i;
  }
  
  line[i] = '\0';/*characters are surrouned by single quotes*/
  return i;
}

int main()/*main return an integer*/ 
{
  char line[SIZE];
  int c;
  int sizeOfArray = sizeof line/sizeof(int);

  while(c == getline(line, SIZE))/*comparion not equals*/
	printf("%c", (for(int i=0; i<sizeOfArray; i++) line[i]));/*have no idea what our doing here*/

  return 0;
}
gerard4143 371 Nearly a Posting Maven

I always thought that the GCC(mingw) compiler accepted AT&T syntax for inline assembler.

gerard4143 371 Nearly a Posting Maven

All through this program...What's the value of r?

gerard4143 371 Nearly a Posting Maven

Shouldn't you have a closing brace on line 32.

gerard4143 371 Nearly a Posting Maven

try to include the header unistd.h

What you think this is a Unix/Linux based system?

gerard4143 371 Nearly a Posting Maven

Depends, what's the error?