gerard4143 371 Nearly a Posting Maven

Hello guys, I'm trying to make this work

all: daemon client

daemon:	
	cd ./daemon; make daemon
client: 
	echo going in
	cd ./client; make client
clean:
	cd ./daemon ; make clean
	cd ./client ; make clean

But I'm having 2 problems:
1) Make ALWAYS tells me there's nothing to be done. Wether I try to make daemon, client or all. The echo command doesn't even seem to work.
Edit: turns out I can't use the command "make daemon" on both the main makefile and the secondary makefile.


2) Clean DOES work but it doesn't clean the client if cleaning the daemon failed.

So you have makefiles in the ./client and ./daemon
directories?

Plus I've always seem makefiles like

all: daemon client

daemon:	
	cd ./daemon
	make daemon
client: 
	echo going in
	cd ./client
	make client
clean:
	cd ./daemon
	make clean
	cd ./client
	make clean
gerard4143 371 Nearly a Posting Maven

Then yes I agree that you can mimic getline with getchar/getc/fgetc

gerard4143 371 Nearly a Posting Maven

that does not use any external libraries

I must of misinterpreted this line

gerard4143 371 Nearly a Posting Maven

I didn't mean that at all. I believe that it is quite possible to do a simple 'getline' function by using getchar. It would be limited, yes, but it could be done. I don't have a copy of K&R2 at the moment, but I believe they implement (in the book) something like what I am talking about.

Edit:

There is an example of what I am talking about here.

Yes but getchar requires external libraries since it requires systems calls to interact with the stream which is maintained by the operating system....Or are we talking about a non-standard C compiler

gerard4143 371 Nearly a Posting Maven

Maybe you could write your own function, and call it...oh, I don't know... getline? :idea:

This guy's having problems with a simple user app an you want him to interface with the system calls directly and create a function that will mimic getline?

gerard4143 371 Nearly a Posting Maven

I actually found the problem....google "getline solaris". Because I am on a Sunblade(Solaris) I cannot use getln, fgets, or basically anything other than string.h which is not supposed to be used for this program. My next way of attempting to simply solve the program will be to copy every individual character into an array using getchar and then begin copying the array into a second array that has an if statement that checks if it is a whitespace character duplicate before copying. Can anyone think of any better way to do this that does not use any external libraries or getline, getln, fgets?....basically just getchar() and putchar()

I'm confused by this???Why can't you use C standard libraries? This is a C program right? How do you intend to know for sure if the stripping is correct if you can't display or save the answer...

gerard4143 371 Nearly a Posting Maven

Dumb question, did you include stdio.h

gerard4143 371 Nearly a Posting Maven

Number one your posting title is misleading "Problem with fork system call". The system call is working just the way its supposed to. I kind of see what your trying to do here, copy a file and display its progress at the same time...this to me sounds like a problem for threads

gerard4143 371 Nearly a Posting Maven

Do you mean all combinations that are words or do you mean all combinations of the letters regardless if they form a correct word?

gerard4143 371 Nearly a Posting Maven

Oh I see

import string
global L

def second(s):
    global L
    L=string.split(s)
     print(s)
     print(L)

Then refer to it(after you import it into the main app) like
twond.L

gerard4143 371 Nearly a Posting Maven

Why don't you def your function like

def second(s):
    str = string.split(s)
    return str

then you can print it like

print str(second(string))

gerard4143 371 Nearly a Posting Maven

I am using the file ex3test.c to run the following program, but the UNIX gives the errors:

[38] $ gcc -o ex3test ex3test.c


Do you mean when you compile ex3text.c it gives you errors

gerard4143 371 Nearly a Posting Maven

If I understand this you have the hard part all figured out. Just prompt for the numbers in your for loop and add them up and the divide by the total

gerard4143 371 Nearly a Posting Maven

Why don't you use the Python interpreter...It does a great job of parsing

gerard4143 371 Nearly a Posting Maven

try x ==1 or x == 2 your version is always true x ==1 or 2 since 2 is not 0 so anything or'd with a true value is true

gerard4143 371 Nearly a Posting Maven

Sorry didn't mean to come off as uppity maybe you should check some of the open source encryption libraries that are available....G4143

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

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

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
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

Try the break statment

gerard4143 371 Nearly a Posting Maven

Looks good

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 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


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

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?

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?