gerard4143 371 Nearly a Posting Maven

And what's the problem?

gerard4143 371 Nearly a Posting Maven

You should get into the habit of initializing data member like so

Vector::Vector ()
:x = 0,y = 0,z = 0 
{}

Vector::Vector (float a, float b, float c) 
:x = a,y = b,z = c
{}

In some situations its more efficient.

gerard4143 371 Nearly a Posting Maven

Its very common to reassign pointers... So your line 14 is valid.

gerard4143 371 Nearly a Posting Maven

Hi guys again,
I have tried the code and it doesnt seem to work.

In the other hand I have manipulate the code so that I have a function to display all customers and this is working!!!
:(

What code? You'll have to post it if you want us to look at it.

gerard4143 371 Nearly a Posting Maven

Try looking at the attached code...It may help straighten things out or it just might confuse you more..

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

int main()
{
	int i = 0;
	int *iptr = (int*)malloc(sizeof(int) * 10);
	int **tptr;

	for (i = 0; i < 10; ++i)
		*(iptr + i) = i;

	for (i = 0; i < 10; ++i)
		fprintf(stdout, "ans->%d\n", *(iptr + i));

	tptr = &iptr;

	for (i = 0; i < 10; ++i)
		fprintf(stdout, "ans->%d\n", *(*tptr + i));
	
	return 0;
}

I really should have used C++, so here look at this one

#include <iostream>

int main()
{
	int i = 0;
	int *iptr = new int[10];
	int **tptr;

	for (i = 0; i < 10; ++i)
		*(iptr + i) = i;

	for (i = 0; i < 10; ++i)
		std::cout << "ans->" << *(iptr + i) << std::endl;

	tptr = &iptr;

	for (i = 0; i < 10; ++i)
		std::cout << "ans->" << *(*tptr + i) << std::endl;
	
	delete [] iptr;
	
	return 0;
}
gerard4143 371 Nearly a Posting Maven

Its the same for both examples.

gerard4143 371 Nearly a Posting Maven

Your going about this the wrong way. Customers member function 'showCustomers' shouldn't loop through the Customers objects, it should only display its values.

You should have a loop like

for (int i = 0; i < 150; ++i)
{
CustArray[i].showCustomers();
}
gerard4143 371 Nearly a Posting Maven

Your Hi variable

char Hi[4] = {'3','E','2','C'};

is four bytes with the values of(in ascii)
0x33 = '3'
0x45 = 'E'
0x32 = '2'
0x43 = 'C'

and this (in ascii)

Bye[0] = 0x3E and Bye[1] = 0x2C

would equate to

Bye[0] = '>' and Bye[1] = ','

I think your mixing up characters and their acsii values.

gerard4143 371 Nearly a Posting Maven

Try working with setprecision like below

#include<iostream>
#include <iomanip>


int main()
{
	double my_f = 1.0/3.0 / 30.0;
	std::cout << my_f << std::endl;
	std::cout << std::setprecision (100) << my_f << std::endl;


}
gerard4143 371 Nearly a Posting Maven

The memory manager is choking on your pointer 'p' because you incremented its value.

Check the enclosed code..

#include<iostream>
using namespace std;

int main()
{
  int* p=new int[2];
  p[0]=1;
  p[1]=2;
  cout<<p[0]<<" "<<&p[0]<<endl;
  cout<<p[1]<<" "<<&p[1]<<endl;
  cout<<endl;
  cout<<*p<<" "<<p<<endl;
  p++;
  cout<<*p<<" "<<p<<endl;
  p--;//set pointer back to its original value
  delete [] p;
}
gerard4143 371 Nearly a Posting Maven

If your going to increment your pointer then save its original value somewhere and delete that.

gerard4143 371 Nearly a Posting Maven

Line 19...Why are you closing write here?

actually line 16...Why are you opening write here?

Try looking at the code below

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

#define BSIZE 24

int main()
{
	char ch[BSIZE];
	FILE *fout;
	FILE *fin;

	if (!(fin = fopen("testfile", "r")))
	{
		fputs("could not open testfile!\n", stderr);
		exit(EXIT_FAILURE);
	}

	if (!(fout = fopen("testout", "w")))
	{
		fputs("could not open testout!\n", stderr);
		exit(EXIT_FAILURE);
	}

	while (fwrite(ch, sizeof(char), fread(ch, sizeof(char), BSIZE, fin), fout))
	{
	}

	fclose(fout);
	fclose(fin);
	return 0;
}
gerard4143 371 Nearly a Posting Maven

This code has some things that you should avoid like

fflush(stdin);

This is a no no.

Plus this

PATIENT_DATA section_1[40]= {"","","","",0,"","","","",0};

I'm not sure what the effect is here...Does it initialize the first element? I'm not really sure, one of the C language lawyers will have to comment on this one..

Here's a cleaned up version of the posted code

#include <stdio.h>

typedef struct
{
	char first_name[20];
	char middle_name[20];
	char last_name[20];
	char illness_type[5];
	int patient_number;
	char doctor_fname[20];
	char doctor_lname[20];
	char emer_fname[20];
	char emer_lname[20];
	int emer_telephone;
} PATIENT_DATA;

int main()
{ 

	PATIENT_DATA section_1 = {"","","","",0,"","","","",0};
	printf("\nPatient First Name: ");

	fgets(section_1.first_name, sizeof(section_1.first_name), stdin);

	return 0;
}

Please note, if you post code use the code tags.

gerard4143 371 Nearly a Posting Maven

Does your file have a main function? Plus could you post your compile line or makefile?

gerard4143 371 Nearly a Posting Maven

Can we see what you have so far?

gerard4143 371 Nearly a Posting Maven

Instead of having a function that removes duplicates, why not design the linked list functionality so that it will not accept duplicates..e.g. inserting a new node that results in a duplicate will do nothing.

gerard4143 371 Nearly a Posting Maven

Hi guys,thanks for the remedies.However on using fgets the compiler generated two errors of the same nature.It was like 'too few arguements passed to function 'fgets''.I am trying to read more about fgets and I will see what i'll come up with.For now thanks!

Take this in the way its intended...or not. Did you actually google how to use fgets()?

gerard4143 371 Nearly a Posting Maven

gerard4143
thanks but make it simple
i am suppose to input names and stored in vector
after that i am suppose to use another function to write out the names in vector
i am suppose to also use another function to save the vector.
it will be of great pleasure if i you can help me with that.
sorry for asking baby question

No, if you'll check your original posting you said list...

gerard4143 371 Nearly a Posting Maven

Well if your allowed to utilize the list container then its pretty simple

#include <list>

/*creat list*/
std::list<data structure/class> my_list;
/*add to list*/
my_list.push_back(data structure/class);
/*display list*/
copy(my_list.begin(), my_list.end(), std::ostream_iterator<data structure/class>(std::cout, " "));

The rest you can figure out.

gerard4143 371 Nearly a Posting Maven

And I say again...Adak pretty much solves it for you. Please look at his posting.

gerard4143 371 Nearly a Posting Maven

First question. Are you allowed to use the Standard Template Library?

gerard4143 371 Nearly a Posting Maven

Your created an array of structures

struct secguard guard_rec[300];

So to access one element of your array you must use an array index like

gets(guard_rec[0].first_name);

Oh by the way the use of gets is really frowned upon...really. Here's why

BUGS
Never use gets(). Because it is impossible to tell without knowing the
data in advance how many characters gets() will read, and because
gets() will continue to store characters past the end of the buffer, it
is extremely dangerous to use. It has been used to break computer
security. Use fgets() instead.

Ooops Narue got here first

gerard4143 371 Nearly a Posting Maven

Line 81 in your posted code, your calling two member functions but your not passing any arguments.

This

OriginalData.EnterData;		OriginalData.DisplayData;

Should be

OriginalData.EnterData(argument list);		OriginalData.DisplayData(argument list);

I tried compiling your code and got a few errors...here they are

g++ testit.cpp -Wall -ansi -pedantic -o testit
testit.cpp: In function ‘int main()’:
testit.cpp:81: error: statement cannot resolve address of overloaded function
testit.cpp:81: error: statement cannot resolve address of overloaded function
testit.cpp: In member function ‘void TheData::EnterData(TheData&)’:
testit.cpp:205: error: ‘exit’ was not declared in this scope
testit.cpp: In member function ‘void TheFilter::EnterFilter(TheFilter&)’:
testit.cpp:309: error: ‘exit’ was not declared in this scope
testit.cpp: In member function ‘int TheFilter::ApplyFilter(TheData, TheFilter, TheData&)’:
testit.cpp:26: error: ‘long unsigned int TheData::Length’ is private
testit.cpp:327: error: within this context
testit.cpp:25: error: ‘double* TheData::Values’ is private
testit.cpp:330: error: within this context
testit.cpp:26: error: ‘long unsigned int TheData::Length’ is private
testit.cpp:331: error: within this context
testit.cpp:26: error: ‘long unsigned int TheData::Length’ is private
testit.cpp:331: error: within this context
testit.cpp:25: error: ‘double* TheData::Values’ is private
testit.cpp:334: error: within this context
testit.cpp:26: error: ‘long unsigned int TheData::Length’ is private
testit.cpp:334: error: within this context
testit.cpp:25: error: ‘double* TheData::Values’ is private
testit.cpp:336: error: within this context
testit.cpp:339: error: ‘exit’ was not declared in this scope
testit.cpp:26: error: ‘long unsigned int TheData::Length’ is private
testit.cpp:343: error: within this context
testit.cpp:25: error: ‘double* TheData::Values’ is private

gerard4143 371 Nearly a Posting Maven

Maybe you can start by giving us the basics...Does it compile error/waring free? If not which errors and warnings are generated? Is it a run time problem? If so what's the problem? We need more than 'is not running anymore'.

gerard4143 371 Nearly a Posting Maven

Just refer to Adak's posting, he pretty much solves it for you.

gerard4143 371 Nearly a Posting Maven

Try working with the modulus operator...Like below

#include <stdio.h>

int main(int argc, char**argv)
{
	fprintf(stdout, "%d\n", 12345 % 10);
	fprintf(stdout, "%d\n", 12345 % 100);
	fprintf(stdout, "%d\n", 12345 % 1000);
	return 0;
}

This should give you a good start...

gerard4143 371 Nearly a Posting Maven

@kamatari..not yet..!!!
bt i am thinking of making a game and it will surely take time.
our teachers has informed us about dis project at the last moment.

If the teachers dumped this project on the class 'at the last moment' then I expect the class and yourself will have to 'do the best you can'.

jonsca commented: Well put. +6
gerard4143 371 Nearly a Posting Maven

Which one are you talking about? I tried compiling your program and got several warnings and errors.e.g

gcc testc.c -Wall -ansi -pedantic -o testc.c
testc.c: In function ‘main’:
testc.c:12: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[20]’
testc.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
testc.c:14: warning: implicit declaration of function ‘scandir’
testc.c:14: error: ‘alphasort’ undeclared (first use in this function)
testc.c:14: error: (Each undeclared identifier is reported only once
testc.c:14: error: for each function it appears in.)
testc.c:15: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
testc.c:16: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
testc.c:10: warning: unused variable ‘statBuf’
gerard4143 371 Nearly a Posting Maven

Mysql has this great site with all this info and tuorials

http://zetcode.com/tutorials/mysqlcapitutorial/

gerard4143 371 Nearly a Posting Maven

Your example on line 3

someFN( &classInstance );

This passes the address of classInstance not the reference of classInstance.

gerard4143 371 Nearly a Posting Maven

Try changing line 29 to

myQ.AddMSG(myNewMessage);

gerard4143 371 Nearly a Posting Maven

Try this

g++ testit.cpp -E testit >testfile

gerard4143 371 Nearly a Posting Maven

Well if you needed negative values then you would use signed char.

gerard4143 371 Nearly a Posting Maven

I would use the functions toupper or tolower to make your code portable.

int ans = toupper(val);
if (ans == val)
{
/*is upper case*/
}
else
{
/*is lower case*/
}
gerard4143 371 Nearly a Posting Maven

First, datatype_ptr is a pointer to a block of memory that contains the structure elements. When you use datatype_ptr->b the compiler may(I say may because it really depends on how the memory's allotted for your structure) use masking operations to access the value stored at datatype_ptr->b..

"Does stucture- or bit field datatype usage increase execution and calculation speed?"

Generally no, the added masking operations will create more code.

gerard4143 371 Nearly a Posting Maven

I didn't read your post in its entirety but I can inform you about this...On Intel/AMD machines the smallest addressable memory is a byte. If you have to work with bits they are not directly addressable so you have to use masking operations to access them...e.g. You can't point a memory pointer at bits only bytes.

gerard4143 371 Nearly a Posting Maven

Ancient Dragon and vijayan121 thank-you for your answers and book recommendation. Inside the C++ Object Model I'll have to check out that book..Again thanks for your answers..G

gerard4143 371 Nearly a Posting Maven

Hi,

Is there ever a situation where the programmer needs to be concerned about the copying of a vtable pointer or can I happily assume that the C++ language will handle that detail correctly without my intervention?

gerard4143 371 Nearly a Posting Maven

Why are you reviving a thread dated - Jan 24th, 2008?

gerard4143 371 Nearly a Posting Maven

Just a point...Is it a good idea to call your thread array main[];

Also..

int x[50];
int y[50];

void *run(void *i)
{
      int trial = (int)i;
      int mode;
      int Xcor[50];
      int Ycor[50];
      while (trial!=10)
      {
       mode = rand() % 50;
       x[trial]=Xcor[mode];
       y[trial]=Ycor[mode];
      }
      pthread_exit(NULL);
}

Your accessing the global resources

int x[50];
int y[50];

from more than one thread?

gerard4143 371 Nearly a Posting Maven

Is there a toUpper or toLower in C/++ ?

The ctype.h library has functions

int toupper(int c);
int tolower(int c);

gerard4143 371 Nearly a Posting Maven

"warning: incompatible implicit declaration of built-in function 'malloc'"

Are you including stdlib.h?

gerard4143 371 Nearly a Posting Maven

WaltP I don't disagree with your reasoning, I'm just stating that the variable is still sizeof(int) in size...Its probably cutting hairs but that's just the way I am..

gerard4143 371 Nearly a Posting Maven

That sounds even more convoluted.
You could clear out the bits you don't want: i = i & 0xFFFFFF; to make the value 24 bits.

I'm not trying to start an argument but your solution still has the original amount of bits, its not 24 bits but 32 bits with a masking operation..Maybe I misunderstood the op?

gerard4143 371 Nearly a Posting Maven

I would look at two for loops

for (int i  0; i < x; ++i)
{
	for (int j = 0; j < y; ++j)
	{

	}
}
gerard4143 371 Nearly a Posting Maven

Here's the output from my computer

Parent Writing [0]...
Parent Writing [1]...
hello there
Parent Writing [2]...
Parent Writing [3]...
Parent Writing [4]...
Parent Writing [5]...
Parent Writing [6]...
Parent Writing [7]...
Parent Writing [8]...
Parent Writing [9]...
[gerard@localhost test]$ hello there
hello there
hello there
hello there
hello there
hello there
hello there
hello there
hello there

[g@localhost]$

Just hit the enter key when the program is over.

gerard4143 371 Nearly a Posting Maven

You could try a union with a packed structure..If you using MS you'll have to Google to find out how to pack a structure...

#include <stdio.h>

union mu
{
	int x;
	struct
	{
		unsigned int a:8;
		unsigned int b:24;
	}__attribute__((packed)) in;
};

int main(void)
{
	union mu theu;
	theu.x = -1;

	fprintf(stdout, "%x\n", theu.in.b);
	return 0;
}

Output

ffffff

gerard4143 371 Nearly a Posting Maven

Well quickly, the function 'ChatPrintf' is collecting its arguments in a 'buffer' szBuffer according to the format string 'const char *format' and then handing the buffer off to your function pointer 'ChatPrint'.

If you hope to understand this please read this link..

http://www.cprogramming.com/tutorial/lesson17.html

gerard4143 371 Nearly a Posting Maven

Why would you want to translate something that's hard wired to a specific address?

typedef void (*t_ChatPrint) ( char * );
t_ChatPrint ChatPrint = (t_ChatPrint)0x0054E410;

Your function pointer ChatPrint is hard wired to 0x0054E410..

Can I ask you a question? Why are you translating code when you don't even know its function.

gerard4143 371 Nearly a Posting Maven

An array define like so

int my_array[4];

has elements 0 - 3 not 0 - 4