gerard4143 371 Nearly a Posting Maven

Is Account Account::operator+(const Account & rhs);
defined in Account class or is it external to the Account class?

gerard4143 371 Nearly a Posting Maven
Account operator+(Account &right)

should be

Account Account::operator+(const Account &right)
gerard4143 371 Nearly a Posting Maven

gerard4143, you're still using operator (-)

Whoops...busted

and the ++ operator in the for statement

gerard4143 371 Nearly a Posting Maven
#include <iostream>

unsigned int addone(unsigned int x)
{
	unsigned int y = 0;
	unsigned int z = 0;

	for (int i = 0; i <= 31; ++i)
	{
		z = (x<<(31 - i))>>31<<(i);
		if (z > 0)
		{
			x = x ^ z;
		}
		else
		{
			y = x|0xffffffff;
			z = (y<<(31 - i))>>31<<(i);
			x = x ^ z;
			return x;
		}
		
	}
	return 0;
}

int main(int argc, char**argv)
{	
	unsigned int x = 0;


	while (true)
	{
		std::cout<<"enter a value, 0 to exit->";
		std::cin>>x;
		std::cout<<"\n";

		if (x <= 0) break;

		std::cout<<"x->"<<x<<"\n";
		std::cout<<"addone->"<<addone(x)<<"\n";	
	}
	return 0;
}

This will increment with out the math operators

This is a member of the ugly code club

joshSCH commented: Pay attention. -2
gerard4143 371 Nearly a Posting Maven

Hi,
What I'm looking for is some good books on C or gas assembler. I would prefer the books be Linux based. So if you know any good titles could you pass them on to me...Thanks

gerard4143 371 Nearly a Posting Maven

how to write program with void as data type

void *myvoid ;
gerard4143 371 Nearly a Posting Maven

The easies way to handle this is to stop using cin and use getline() to read the entire line as a string. Then you can pull off (convert to number) the integer part and actually throw out the rest of the line.

If you read the prevous post you see that what I posted using

while ((ch[0] std::cin.get) != '\n')
                {
                          if (isdigit(ch[0]))
                                      ....etc
                }
gerard4143 371 Nearly a Posting Maven

If it has to be an integer then use isdigit to check that each character of the input is a digit.

a simp,e way to do this is

char ch[2];
ch[1] = '\0';
int x = 0;
const int MULTI = 10;

	std::cout<<"enter a number->";
	while ((ch[0] = std::cin.get()) != '\n')
	{
		if (isdigit(ch[0]))
		{
			x = (x * MULTI) + strtol(ch, NULL, 10);
		}
                else
               {
                      std::cout<<ch[0]<<" error message\n";
                     //or you could throw and exception
               }
	}
	std::cout<<"x->"<<x<<"\n";

this is only a suggestion, but may use it if you like it

This does report the problem value all you had to do was put an else in the if statement. Plus this will
report any values that are not digits i.e not integers. Why the language allows this type of behavior (enter floats values for ints then looping forever)to keep it light wieght. i.e. if you wanted the functionality you should have to developed it into the application. That's my understanding

gerard4143 371 Nearly a Posting Maven

If it has to be an integer then use isdigit to check that each character of the input is a digit.

a simp,e way to do this is

char ch[2];
ch[1] = '\0';
int x = 0;
const int MULTI = 10;

	std::cout<<"enter a number->";
	while ((ch[0] = std::cin.get()) != '\n')
	{
		if (isdigit(ch[0]))
		{
			x = (x * MULTI) + strtol(ch, NULL, 10);
		}
	}
	std::cout<<"x->"<<x<<"\n";

this is only a suggestion, but may use it if you like it

gerard4143 371 Nearly a Posting Maven

I seen something like this in linux socket programming. Try using a socklen_t pointer. The worst that can happen it won't work.

gerard4143 371 Nearly a Posting Maven

Did look it up. Interesting topic. Just finished writing a c program to implement mysql_real_escape_string the mysql cure for SQL injection. Its a little rough right now but it works.

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

int main (int argc, char**argv)
{
	char ch[] = "this is a string\n";
	char ch2[] = "this is a string with 'embedded' quotes\n";

	printf ("%s",ch);
	printf ("%s",ch2);
	return 0;
}

If you need to see how to embedded quotes in a string see above
Note you really should have posted this on the c page

gerard4143 371 Nearly a Posting Maven

That will always return TRUE, which is what an SQL injection attack is.

I'm not sure what an SQL injection attack is but I have produced dynamic query strings for mysql in c/c++ and its not that hard. The way I did (in c++) was to create a string class and use this to build my query string and then pass it to the mysql function. If you are using c you should read up on the string library that might help.

gerard4143 371 Nearly a Posting Maven

I know nothing more than that. Sorry.

No problem...Thanks for the interest...Gerard4143

gerard4143 371 Nearly a Posting Maven

What I have problems understanding is when you subl $4, %esp (AT&T syntax sorry) and increase the program's memory how does the operating system know to validate this increases. I have a very simple understanding of this process but would like a more techincal understanding....Thanks Gerard

gerard4143 371 Nearly a Posting Maven

Just build a character array based on user input then pass it to mysql.

char querystring[100];

mysql_query(conn, querystring);

this is the easiest way.

gerard4143 371 Nearly a Posting Maven

the way you have your sential set up (goto start) your program will never end without a with a ctrl-c, plus your if statements in the wrong place.

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

int main ()

{
	int selection;
	float sum, difference, product, quotient;
	float num1, num2;


start:

	printf("****************************\n");
	printf("What would you like to do?\n");
	printf("1 = add \n2 = subtract \n3 = multiply \n4 = divide \n5 = exit\n");
	printf("***************\n");
	printf( "Enter your selection:");
	scanf("%d", &selection);
	printf("Please enter the first number:");
	scanf("%f", &num1);
	printf("Please enter the second number:");
	scanf("%f", &num2);
	printf("*************************\n");

	if ( selection==1 || selection==2 || selection==3 || selection==4 ) 
	{
		switch (selection)
		{

		case 1:
			sum = num1 + num2;
			printf("Operation Result: %.2f\n", sum);
			break;
		case 2:
			difference = num1 - num2;
			printf("Operation Result: %.2f\n", difference);
			break;
		case 3:
			product = num1 * num2;
			printf("Operation Result: %.2f\n", product);
			break;
		case 4:
			quotient = num1 / num2;

	if( num2==0)
	{
		printf("The denominator cannot be zero.\nRe-enter denominator: ");
		scanf("%f", num2);
		printf("Operation Result: %.f\n", quotient);
		break;
	}
	else 
		printf("Operation Result: %.2f\n", quotient);
		break;
	}
	}

	if (selection<0 || selection >5)
		printf("Invalid Operation Selected\n");

goto start;


	if (selection==5)
	{
		printf( "Thanks for using this program. Bye Bye!!\n");
	}

return 0;
}
gerard4143 371 Nearly a Posting Maven

Since this program has some problems, could you tell us in words what you are trying to do here.

gerard4143 371 Nearly a Posting Maven

My questions is a simple/hard one, whats a stack on an intel machine? I don't a need lesson on how to use one for I already know how, its just that I really don't know very much about them. Like how come you can automatically allocate memory on them by simply moving the stack pointer. Is this just the way its designed, the intel chip, increase or decrease the value in esp and increase or decrease memory available to the program. Can a user program create stacks as needed?
I guest what I,m looking for is a really detailed article on the stack for intel cpus

So if anyone knows of a good website please let me know

Thanks in advance...Gerard4143

P.S. I have read the 4 big Intel Manuals

gerard4143 371 Nearly a Posting Maven

you should use gcc -o filename filename.c

this will produce a exe thats called filename instead of a.out

gerard4143 371 Nearly a Posting Maven
unsigned int a = (int)0xffff0000;
	unsigned int b = 0;

	for (int i = 31; i >= 0; --i)
	{
		b = b + ((a>>(31 - i))<<(31)>>(31 - i));
	}

	return 0;

this will also work...member of the ugly code club

gerard4143 371 Nearly a Posting Maven

Not really sure what you mean...Could you give us an example?

gerard4143 371 Nearly a Posting Maven
unsigned int a = (int)0x12345678;
unsigned int b = 0;
int i = 0;

	for (i = 31; i > 0; --i)
	{
		b = b + ((a>>(31 - i))<<(31)>>(31 - i));
	}

this will also work...member of the ugly code club

gerard4143 371 Nearly a Posting Maven

Collect Collect::operator+(const Collect& c)

should be Collect Collect::operator+(const moive& m)

or some thing close to this since you are adding a movie to the object

gerard4143 371 Nearly a Posting Maven

Collect Collect::operator+(const Collect& c)

should this be const since you are changing the object;

gerard4143 371 Nearly a Posting Maven

try looking up xor to switch the 0's to 1's and the 1's to 0's.
to rearrange the elements look up shift rigth shift left and rotate rigth and rotate left

gerard4143 371 Nearly a Posting Maven

in gas (linux i386) if we had a label defining a list of bytes, say bytelabel, we would move through that list like

xorl %edi, %edi
movl bytelabel(, %edi, 1), %eax
incl %edi

gerard4143 371 Nearly a Posting Maven

not sure if this is what you mean, but try

friend std::istream& operator>>(std::istream & in, classname & rhs)

the rest you can figure out

gerard4143 371 Nearly a Posting Maven

try the modulus operator %

ie

int x = (71011 % 70000);

and x = 1011

gerard4143 371 Nearly a Posting Maven

Found the answer on my own.
leal returns the address of a label or memory reference.

gerard4143 371 Nearly a Posting Maven

Is the opcode leal(load effective address) primarly used to calculated the address of
a value that was pushed on the stack?

If anyone knows of any good web sites on this topic could you pass it on to me.

Thanks in advance....Gerard4143

gerard4143 371 Nearly a Posting Maven

a string in c/c++ is a array of characters so extract then like so

#include <iostream>


int main(int argc, char**argv)
{
char *insert = "abcdefg";



for (int i = 0; i < 7; ++i)
std::cout<<insert<<"\n";


}
gerard4143 371 Nearly a Posting Maven

Makefile:

obj−m += hello−1.o
all:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean


make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules should be tabbed in and
make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean should also be tabbed in like below
note: <tab> = tab space

Makefile:

obj−m += hello−1.o
all:
<tab>make −C /lib/modules/$(shell uname −r)/build M=$(PWD) modules
clean:
<tab>make −C /lib/modules/$(shell uname −r)/build M=$(PWD) clean

gerard4143 371 Nearly a Posting Maven

Do you mean a TSR program(termiate stay resident)

gerard4143 371 Nearly a Posting Maven

try flushing the data

gerard4143 371 Nearly a Posting Maven

I need to write a program that runs in the background without a gui window or a console window. It also needs to recognize when a key is pressed. Is there any way to do that? And if yes, then how?

Any and all suggestions would be great. thanks.

yeah re-write your device driver