gerard4143 371 Nearly a Posting Maven

First random by function is not random...no matter what they call the function it is predictable...

Second you really should read up on this field "encryption", its big and diverse I doubt you came up with a new idea..

I really hate to busting bubbles but the truth is encryption is a very complex art that usually requires extensive training in mathematics and/or computer science(Master or Phd)

gerard4143 371 Nearly a Posting Maven

Just in case your a complete rookie, the modulus operator is used like this

print (34 % 3)
print (32 % 8)
print (41 % 8)

where % is the modulus operator...Hope this helps

gerard4143 371 Nearly a Posting Maven

Since this is a homework question I can't answer it but I can give you a really big hint – try looking up the modulus operator, its used for this very type of question..

gerard4143 371 Nearly a Posting Maven

You want me to explain something to you that I don't know and you don't understand...

gerard4143 371 Nearly a Posting Maven

I'm not sure what your asking. Do you mean if a = 1000 and b = 10
then a/b which is 1000/10 = 100

So 10 divides 1000 equally..

Is this what you mean?

gerard4143 371 Nearly a Posting Maven

try creating your cow like:

class cow:
	numcows = 0
	def __init__(self, num):
		cow.numcows +=1 
		self.num = num

print cow.numcows		
		
mycow = cow(13)
print mycow.num
print cow.numcows

mycow2 = cow(23)
print mycow2.num
print cow.numcows
print mycow.numcows
print mycow2.numcows
gerard4143 371 Nearly a Posting Maven

try creating your cow like:

class cow:
	numcows = 0
	def __init__(self):
		cow.numcows +=1 
		
		
mycow = cow()
mycow2 = cow()
print cow.numcows
print mycow.numcows
print mycow2.numcows
gerard4143 371 Nearly a Posting Maven

oh but why does every bitfield structure has int size can it have a smaller size?

Yes you can pack the structure, then the size of the structure is the sum of its elements. The reason the bit fields are aligned(or word size) is the CPU can read aligned data more efficiently, so unless you request a packed structure the compiler will use word size where it can....Gerard4143

gerard4143 371 Nearly a Posting Maven

let a struct is declared as


let assume memory for this structure starts at 0x00000000,
then memory layout will be as follows:-
0x00000000 - 0x00000003 : int a
0x00000004 - 0x00000005: char b
0x00000006 - 0x00000007: 0 (this is padding)
0x00000008 - 0x0000000b: int c

for 64bit machine
0x00000000 - 0x00000007 : int a
0x00000008 - 0x00000009: char b
0x0000000a - 0x000000010: 0 (this is padding)
0x00000011 - 0x00000017: int c

in above case if all the bit fields sums less than or equal to 32 bit (size of int, assuming unix, machines, in turbo C compiler sizeof int is 2 bytes) 4 bytes will be allocated for that.

The above lay out only works if the structure is packed. Just try and take sizeof the above structures and you'll see that memory alignment will increase the size allotted for the char variable to word size...

gerard4143 371 Nearly a Posting Maven

if I can break the second loop after running three loops it will work.

After the triple for loop put in the line break like

for (i = 0; i < 3; ++i)
{
//do something
}
break;
gerard4143 371 Nearly a Posting Maven

Its been some time since I did any SQL but won't it be a more natural fit to use UPDATE WHERE to update a record

gerard4143 371 Nearly a Posting Maven

If you don't want an endless loop why did you write one into your program?

gerard4143 371 Nearly a Posting Maven

The unnamed fields may just be padding so that the structure's data is laid out correctly...Gerard4143

gerard4143 371 Nearly a Posting Maven

Try the appy(functionname, (args)) statement

def printit():
	print "hello, world!"

ch = input("enter a func->")

apply(ch, ())

Now at the prompt enter the function name printit and apply will execute it

gerard4143 371 Nearly a Posting Maven

This works on my machine

#! /usr/bin/python

#Convert C to F
def Tc_to_Tf():
	Tc = input ("What is the Celsius Temperature ? " )
	Tf = 9.0/5.0 * Tc + 32
	print 'The temperature is ', Tf, ' Degrees Fahrenheit'

Tc_to_Tf()
gerard4143 371 Nearly a Posting Maven

Well John A what about

#include <stdio.h>

void myfunc(int x);

int main (int argc, char**argv)
{
	int x = 123;
	myfunc(x);
	return 0;
}

void myfunc(int x)
{
	int iarray[x];
}
gerard4143 371 Nearly a Posting Maven

So Walt what you are saying...is that C doesn't support dynamic arrays????

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

FILE *playerdata;


int main(void)
{
	int buffer = 11;	
	char name[buffer];
	printf("Please Enter Your Name\n");
	printf("Maximum Length 10 characters\n");
	fgets(name,buffer,stdin);
	playerdata = fopen(name, "w+"); /*create the new file*/
	if (!playerdata)
	{
		printf("it failed!\n");
	}
	else
	{
		fputs(name,playerdata); /*write the players name to the file*/
		fclose(playerdata); /*close the file*/
	
	}

	
	
	return 0;
}

I copied your code and ran it like this...and it worked!

gerard4143 371 Nearly a Posting Maven

playerdata = fopen(name, "W+");

should be

playerdata = fopen(name, "w+");

gerard4143 371 Nearly a Posting Maven

You should check playerdata to be sure its valid

i.e is it NULL or valid

if (!playerdata)
{
        do something if not valid
}

plus you should return 0 in the main function

gerard4143 371 Nearly a Posting Maven

Hi Again,

Well i'm bored and i've decided to do some coding just for practice and i've decided to work on a text based RPG, its only going to be basic due to my own knowledge but i think its doable. unfortunatly i've come accros a problem already and i've only writen a few lines of code.

The code deals with creating new character data, i plan to have all the character data stored in a text file, when the user starts a new game the program will ask for the character name then create a text file with this name write the players name and then close the text file.

heres the code that i have so far, this will eventualy be put into its own seperate function but for now its all in main().

#include <string.h>
#include <stdio.h>
#include "input.c"

FILE *playerdata;

int main(void)
{
	int buffer = 11;
	char name[buffer];
	printf("Please Enter Your Name\n");
	printf("Maximum Length 10 characters\n");
		
	fgets(name,buffer,stdin); 
	playerdata = fopen(name, "W+"); /*create the new file*/
	fgets(name,buffer,playerdata); /*write the players name to the file*/
	fclose(playerdata); /*close the file*/
}

thanks in advance for any help,

-Matt

should be fputs to write to a file

gerard4143 371 Nearly a Posting Maven

try
string *array[arraysize];

then to initialize array[0] = pointer to string
etc....

to derefence *array[0];

gerard4143 371 Nearly a Posting Maven

Hello,
When I have a created a socket (sd) connection and opened a file (fd). How can I send over a file? Create a buffer (char buf[BLOCK] ????)and send over block by block or so? And if so, what is most efficient block size?

Cheers!

Yes send it over be reading blocks of text.
for the buffersize, use const BUFSIZ this should be a good size for the local system

gerard4143 371 Nearly a Posting Maven

It could be that 167 is an extended ascii character

gerard4143 371 Nearly a Posting Maven

. but 167 cannot.. why?

Not sure what you mean "but 167 cannot...why?"

Cannot show A?

gerard4143 371 Nearly a Posting Maven

The books that I purchased are:

The C Programing Language by Kernighan and Ritchie

C: The Complete Referenece by Herbert Schildt

and Beginning Linux Programming by Neils Matthew and Richard Stones

The first two book I highly recommend and the final...I have not had time to read it yet

gerard4143 371 Nearly a Posting Maven
double getfloat(char item[], double min)
{
   int err;
   double ticketcost;
do
   {
   printf("\nEnter a ticket %s greater than or equal to %.0lf: ", item, min);
   scanf("%lf%*c", &ticketcost);
   err = (ticketcost < min);
   if (err) error(min, max);
   }
while (err);
return (ticketcost);
}

max is not define in this function. You can:
1 define as a global const if doesn't change
2 define it in the function

Note value like min max are usually global const
set at the beginning of the programi.e.

const int max = some value;
const int min = some value;

gerard4143 371 Nearly a Posting Maven

First problem you have grandtotal define as a function and variable

More to follow

gerard4143 371 Nearly a Posting Maven

Linux uses an array of function pointers for its system calls....Gerard

gerard4143 371 Nearly a Posting Maven

Try the break statment

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

int main()
{
	int i;
	char name[5];
	for(i=0;i<5;i++)
		scanf("%c",&name[i]);

	for(i=0;i<5;i++)
		printf("%c",name[i]);
	return 0;
}

Compiled and ran your code...it works fine. Note main should return an int

gerard4143 371 Nearly a Posting Maven

/*enter comments here*/

gerard4143 371 Nearly a Posting Maven

if ((first=paper) && (second=rock))

should be if ((first==paper) && (second==rock))

gerard4143 371 Nearly a Posting Maven

Looks good

gerard4143 371 Nearly a Posting Maven

Do you mean if we have 16 bytes,

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16

then rearrage them

9, 10, 11, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5, 6, 7, 8

gerard4143 371 Nearly a Posting Maven

Why are treating num_val like an array?

gerard4143 371 Nearly a Posting Maven

is it okay to initialize it to the unlikely temp when I have to provide validation for temp input between -50 and 130?

Sure -1000 tells the program that the temp(array element) is available. Think of it as a marker or sential to inform the program that this element has not been used yet so it should fail your valiidation test.

gerard4143 371 Nearly a Posting Maven

Well I'm a Linux junkie so someone else will have to help with your XP questions

gerard4143 371 Nearly a Posting Maven

Well the simplest way is to associate the array elements with the hours of the day is temp[0] = initail temp, temp[1] = hour 1 temp, temp[2] = hour 2 temp, ..., temp[23] = final temp

gerard4143 371 Nearly a Posting Maven

Why not make a double temp[24] array initialize the elements(to some unlikely temp say -1000) and then fill then in one at a time(for each hour)

gerard4143 371 Nearly a Posting Maven

Basically i am only interested in the contents of the RAM. If i could get a copy of all of the information in RAM - this is what im after trying to program

Maybe if you explain what you mean by "contents of RAM". Do you mean a varaible's memory, a user process's memory or the physical memory on the machine.

and told us what operating system your working with(ie LINUX, UNIX, MS, Mac)

gerard4143 371 Nearly a Posting Maven

I want to create a program that will copy the contents of RAM to another file.

Do you mean the user processes memory or the complete memory available to the computer?
Because if your looking for the complete memory of the computer its sounds like your trying to hack
the operating system(which I don't know how to do).
But if its the first option look up virtual memory, MMU or if you have an intel chip down load the intel manuals

gerard4143 371 Nearly a Posting Maven


void show_word (char);

{
char InName;
cout << "Enter your name " << endl;
cin >> InName >> endl;

show_word ("hello");
show_word ( string InName);

}

this will produce recursion, show_word calling show_word and never end and thats just the beginning

gerard4143 371 Nearly a Posting Maven

yes that's right and to correct the problem use

std::cin.ignore(1);
gerard4143 371 Nearly a Posting Maven

If you look on the main C++ page in Daniweb you will see a posting "How do I flush the input stream".
This should help

Roebuc commented: Thank you for pointing me to that thread. +1
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

I have to go so I leave with an properly working example of the operator+ and operator=
Hope this helps...Gerard4143

#include <iostream>

class number
{
public:
	number(int n):num(n) {}
	~number() {}
	number operator+(const number &rhs);
	number& operator=(const number & rhs);
	int getitsvalue() const {return num;}
	void setitsvalue(int val) {num = val;}
	friend std::ostream& operator<<(std::ostream & out, const number & rhs);
private:
	int num;
};
std::ostream& operator<<(std::ostream & out, const number & rhs)
{
	out<<rhs.getitsvalue();
	return out;
}
number& number::operator=(const number & rhs)
{
	if (this == &rhs)
		return *this;
	setitsvalue(rhs.getitsvalue());
	return *this;
}
number number::operator+(const number &rhs)
{
	number temp(getitsvalue() + rhs.getitsvalue());
	return temp;
}
int main (int argc, char**argv)
{
	number x(123);
	number y(234);
	number ans(0);

	ans = x + y;

	std::cout<<"ans->"<<ans<<"\n";
	return 0;
}
gerard4143 371 Nearly a Posting Maven

error C2662: 'getchecking' : cannot convert 'this' pointer from 'const class Account' to 'class Account &'
Conversion loses qualifiers

temp2 = (savings + right.getchecking());
	}

This error message tells me that the function getchecking is trying to change the value(s) of Account right. You can change the const Account & right to Account & right but you shouldn't have to if the operator+ is set up correctly

gerard4143 371 Nearly a Posting Maven

I think I can clear something up, are you overloading operator=(equals operator) ?
If you are not then set your operator+ to:

Account Account::operator+(Account & right);

gerard4143 371 Nearly a Posting Maven

If I switch it over to the way you just posted, I get the following error:

error C2662: 'getchecking' : cannot convert 'this' pointer from 'const class Account' to 'class Account &'
Conversion loses qualifiers

That is when I use this code

Account Account::operator+(const Account &right)
	{
		Account temp;
		int temp2;
		temp2 = (savings + right.getchecking());
		temp.setTotalBalance(temp2);
		return temp;

	}

--

And the way I was trying to fix it didn't work, so back to step one, looking for what could be doing it.

-- Edit--

Looking back at that, since you input the data after running the program, none of the values are constant, which is the reason for that error I believe.

does getchecking() change Account in any way?