devnar commented: Well explained. Thanks. +1
Murtan 317 Practically a Master Poster
Salem commented: Nicely put +25
Can you TRY to use some of what you got?
If its not quite right, change it a little.
Try starting the loop like this:
while house[5] == "Empty":
print "Pick an item to fill in the empty space: \n1 - Lamp\n2 - bed\n3 - NDS\n\n"
You will have to indent the other lines that should be in the loop.
Python lists support several methods for example: append, count, extend, index, insert, pop, remove, reverse, sort
None of the characters ever "HAVE" to match anything.
The way it works is something like this:
Lets say we have a char * date that points to "01/12/2009" which is in memory as '0','1','/','1','2','/','2','0','0','9','\0'
when you call strtok(date, "/") it actually returns a pointer to the first character and modifies the memory to look like this: '0','1','\0','1','2','/','2','0','0','9','\0'
note that it changed the first '/' into a '\0'.
When you call strtok(NULL, "/") it remembers the last place that it changed and starts searching from there. So it steps to the next character (following the one it changed to '\0') and compares it to the delimiter '/' in this case. '1' isn't '/' so it steps again and keeps looking. '2' isn't '/' either so it steps again. The next chararcter '/' is the delimiter, so it changes it to a '\0' and returns the a pointer to the first character it started with (the '1' in this case). Now the memory looks like: '0','1','\0','1','2','\0','2','0','0','9','\0'
note that the original 'date' still points to the first '0' in that memory string.
Now for the (sarcasm on) all important third call and its delimiter (sarcasm off) when you call strtok(NULL, '/') it does what it did in the last call, but it never finds the '/' so it just returns a pointer to the character following the character it last changed (the '2' in the year). The memory still looks like '0','1','\0','1','2','\0','2','0','0','9','\0'
but the code knows that it …
Looks to me like a template function waiting to happen.
Google (or search here) for C++ templates they let you write code where types can be arguments. This allows you to write functions similar to what you propose.
you're not supposed to take part of the discussion out of the thread...now if someone were to search and find this thread, they can't see what you learned.
For random number generation, I like the python random module:
import random
op1 = random.randint(1,10)
op2 = random.randint(1,10)
sum = op1 + op2
print op1,'+',op2,'=',sum
If the string only contains a date (month/day/year) then you're right the third '/' isn't strictly necessary, but you do need to call it a third time to get the year and the '/' works about as well as anything else that would not be in the 'year' part.
If the string contained a date and a time like (month/day/year hour:minute:second) then the third call would use a ' ', the fourth a ':', the fifth a ':' and the last anything not in the second, but a ':' would work.
That one change fixed almost all the errors in my test project and the remaining error was so blatant I suspect you can solve it.
(If not, post your new code with your new errors and we can look at it again.)
most of your compile errors are in the library headers?
Are you missing a switch (compiler option)?
(I'm trying to compile it in Visual C++ Express and I'm getting an entirely different set of errors.)
The headers (include files) define the names so the compiler knows what things can be done with the name.
The compiler then goes through and genereates symbol references in the object file. For example cout << " deneme "
is a call to a method something like ostream & ostream::operator << (char const *)
which for an ostream puts the string into the output stream. At the object file level, it knows that it needs to resolve the method.
The linker collects the object files with all of their undefined symbols and attempts to resolve them through the list of librarys (both default and specified).
Microsoft C / C++ support an extension that a header file could use to add a default library to search. It is a preprocessor pragma that puts a comment record in the object files: #pragma comment( lib, "emapi" )
(where 'emapi' could be any library name). The end effect when this is encountered by the linker is to add that library to list of default libraries to search for.
It is however uncommon to see them used as if you have different library names based on any compile options, you would have to also detect the compile options to make sure you specify the correct library name.
I'm suspecting you mean alignment of your output, but I'm not sure. It will be very difficult to guide you to a better solution without knowing what you're doing for the alignment presently.
Could you post the following:
The source code for your output function (use code=c++ tags for the source).
A sample of 'good' output (wrap code tags around the output).
A sample of 'bad' output (wrap code tags around the output).
That's not a library reference, that's an include file reference.
The compiler (ok, maybe the preprocessor) will search for a file of the specified name through each of the directories in the include path. It will use the first file it finds. The contents of the file it finds are 'included' as if they were actually typed in that location.
I think your problem is in the call numofdays = daycheck(inday);
daycheck wants the month, not the day.
the test if ((cMenu == 'A' && cMenu == 'a') || (cMenu == 'B' && cMenu == 'b') || (cMenu == 'C' && cMenu == 'c'))
can never be true because the character can not be both the uppercase and lowercase letter at the same time.
With input where the case is not significant, it is common to force it to one case to simplify testing:
cMenu = tolower(cMenu);
if (cMenu == 'a' || cMenu == 'b' || cMenu == 'c')
but in your case, for what you're trying to do, I think this is even better:
while( cMenu == 0 ) // Menu system loop
{
// menu display
printf("\n");
printf("Kudler Fine Foods - Store Selector\n");
printf("\n");
printf("A\tDel Mar Location\n");
printf("B\tThe Encinitas Location\n");
printf("C\tThe La Jolla Location\n");
printf("\n");
printf("Please select a Store: ");
cMenu = getchar(); // input for menu selection
cMenu = tolower(cMenu);
if (cMenu != 'a' && cMenu != 'b' && cMenu != 'c') {
printf("\n");
printf("Invalid Store Selection.\n");
cMenu = 0;
}
} //end cMenu while loop
Note that I did some reformatting of the indenting and I split printf's with embedded newlines. The split printf's are NOT as efficient, but I can better 'see' what the output should be.
I also switched from scanf to getchar for a single character input. ** After further testing, I don't like how getchar() works in this context. I think you should read a line like in the previous post and then find the menu …
That looks pretty close.
Remember that just because fgets() did not return NULL does NOT mean that it read a complete input line. (It is possible for fgets to return with a partial line of data if there is a partial line of data at the end of the file.)
But if the unit need to notify the army that it has died (a little strange in real-life, but not so bad in computers), the unit will need to know which army to notify.
The other option might be for all operations which might 'kill' a unit to come through the army so the army could catch an 'I died' return code to de-list the associated unit.
(sorry missed second page of comments)
try something like:
import random
wl = ["abacus", "biology", "chemistry", "dog", "elf", "ghost"]
random.shuffle(wl)
for word in wl:
print word
We love to help people with their problems, why don't you post what you tried and what you think needs fixed (or why it didn't work) and we will help you fix it.
what does the code look like now (you changed it but didn't repost it)
No, you would be MUCH better off sleeping. If you don't sleep the CPU shows 100% utilization and things slow down, including the other program trying to write the data.
I would start the sleep at 1 second (1000 ms) and wouldn't reduce it unless the performance required it.
No, just declare it. I'm suspecting you'll have a problem when you go to use it.
the prototype called out void *file
. I'm suspecting that it expects a C FILE *
. A FILE * is a result of using the C library to open a file. You appear to be prototyping the argument that is void * file as a ct.c_char_p which I read to be a character pointer (as in a string.) The types are different.
don't use a list when assigning restype: res = bass_dll.BASS_SampleLoad.restype = ct.c_int
But I suspect you're in for a spot of trouble.
a FILE * is NOT a char * fname;
Maybe you should look for a method to disable a control.
(second big hint)
Then I'm all for the 'pay by the line of code' solution. Just paste 100 prints in main and call it good.
As a note, I love using functions to help break things up. You have several things which would support that well.
1) The 'assignment' asks you to fill the board with pairs of numbers from 1-8. On line 15, you fill with a random number from 1 to 8. Where are the pairs?
2) The hints recommended a second array to indicate whether or not a specific card was hidden. That's what you should be updating.
If the two cards match, leave the cards face up, if not, turn them back face down.
You should probably be doing more input validation. (Can the player 're-pick' something where there has already been a match?)
Add a 'while there are cards to match' loop to the code.
where do figure() and show() come from?
They don't exist in python without imports.
What context are you using them in?
Would array initialization be legal?
class Foo {
Foo() { cout << "Hello, World\n"; }
};
int main()
{
Foo myarray[100];
}
don't you need to empty the factors array before you start factoring the next number?
Try factors=[]
just before the for k in range(1):
Yes the getFName did return a constant character pointer. All pointers can implicitly be treated as an array (you just have to be careful not to write where you don't have permission). In this case, it points to the buffer inside the PERSON object and is a pointer to a const char. (The const part encourages the compiler to make it hard for you to write through the pointer accidentally.) You can use this pointer in your code like you would any character array. (Specifically, you can cout << p.getFName();
and will output the first name, just like you might expect it to.)
We don't really need to make a copy of the string unless we plan to modify it. And if we do, we can make the copy using the pointer.
The same thing works in reverse for the setFName() method, except the only thing we do with the pointer is to make a copy of what it pointed to into our buffer.
If you're planning to implement this in C, you're posting in the wrong forum. (I personally use the forum you posted your message into as a guide into how to answer the question.)
I'd have to go back and see what fgets() would do if it reached the 'end of file' without seeing a '\n'. I think it will still fetch the data from the file. As far as the reader program is concerned, the file does not have (and will not have) any more data. The libraray is not aware that more data will be written. You might even have to call some form of reset (to clear the EOF / error status) on the file in the reader to get it to read more data afterward.
then the calls from main to reference the new methods:
case ADDPERSON :
cout << "Enter First Name " << endl;
cin >> fName;
cout << "Enter last Name " << endl;
cin >> lName;
cout << "Enter Address " << endl;
cin >> Address;
p.setFName(fName);
p.setLName(lName);
p.setAddress(Address);
status = access.addPerson(p);
You already had character buffers for the fName, lName and Address declared.
I think you understand the concept. Here's your PERSON class (without the people array) but with some accessors added.
class PERSON
{
private:
char fName[25];
char lName[25];
char Address[100];
public:
PERSON();
char const * getFName() const;
char const * getLName() const;
char const * getAddress() const;
void setFName(char const * fname);
void setLName(char const * lname);
void setAddress(char const * address);
};
Here's an example implementation for a couple of those methods I added:
char const * PERSON::getFName() const
{
return fName;
}
void PERSON::setFName(char const * _fname)
{
strcpy_s(fName, sizeof(fName), _fname);
}
Sounds fairly straightforward then.
Make sure you plan that the reader might be able to get a 'partial' record from the updater. It is possible that the processor might swap from one app to the other before the record is completely written.
For file sharing, look at "FileShare Enumeration" for .Net in MSDN
On one more design note, it looks like you had PERSON and then attempted to add an array to it to make the address book.
I would recommend having an ADDRESSBOOK class that has the array and the members for updating and accessing the PERSON objects in the ADDRESSBOOK.
If I remember right, the JIT debugger from visual studio is enabled (or disabled) as an option from within studio. I think it was under the debugger section.
Generally, you want to avoid the above. I think if you tried hard enough, you might be able to hack something together, but I don't think it would be worth the ongoing effort.
I know in visual studio that once you tell it that one dll (or lib) depends on another one in your solution, that you are then prevented from specifying the depndency in reverse. (It uses dependency to help establish build order.)
If you really have two objects (classes, modules, whatever) that depend on each other that closely, they should be in the same compilation unit (lib, dll, etc.)
as far as code like:
cout << "Enter First Name " << endl;
cin >> p.fName;
cout << "Enter last Name " << endl;
cin >> p.lName;
cout << "Enter Address " << endl;
cin >> p.Address;
where p is an instance of PERSON, it is generally not allowed.
Your options are:
1) make the members public. (bad form, but you could make it work.)
2) add accessors for the dataitems. Methods like setFName(char const * fname)
that will allow you to set the data members. You would have to accept user input into temporary variables and then call the accessor to set the data.
3) add an update that takes all of the fields that might be updated in one call. (Similar to the previous, you still need to use temporary variables.)
4) add a method that would prompt for and accept input into the members. (I think you said you couldn't do that, but I don't know if it was because you couldn't make it work, or if it was not permitted.)
#2 tends to be the most common implementation.
The code as posted has a few problems:
In combination with const int MAXADDRESS = 25;
, the statement char people[MAXADDRESS];
declares an array of 25 characters.
But later in methods of the class, you treat people like it was an array of PERSON.
See: people[head] = p;
and p = people[tail];
for examples. (This shouldn't even compile, doesn't your compiler complain about it?)
You also have methods which you appear to intend to 'return' a value through a PERSON reference. For example: bool PERSON::findPerson(char *lastName, PERSON &p)
appears to search the people array (treating it like an array of PERSON) for a name that matches and assigns to p from the PERSON array. As long as you are aware that at the point of that assignment, the contents of whatever were passed in as 'p' have been overwritten with a copy of the record found, everything is fine. I just wanted to make sure you understood how it works.
Under windows, getting the file open by two programs is a matter of using file sharing modes. The 'reader' would commonly "deny none" the 'updater' would commonly 'deny write'.
The only real concern I have is whether or not the two programs need to interact at all. How does the reader know when all of the data has been read, or does it keep trying to read in case the updater puts more data into the file?
If the second case:
How does the reader know when the data is complete?
How does the reader know that it is 'done'?
I was trying things in a test application. DateTime.Now.ToString("HH:mm:ss")
and DateTime.Now.ToString("hh:mm:ss tt")
both seem to produce valid output.
Does SQL like one format better than the other?
Is time a reserved word? Could you name the column qtime like you did qdate?
Well, you could look at the values in the debugger if you have one, or you could add additional print statements to better confirm the values. If you come to the conclusion that the values are correct then you have to chase back to where they came from to see where they were last correct.
(This is why developing and testing iteratively makes so much sense, you only have to look at the new stuff if something stops working.)
it almost doesn't make any sense to calculate the average as you go along (unless you need intermediate averages).
In the AddDetailToAccumulators() you are dividing the total by MAX to generate the average. Are you always going to read MAX values?
Secondarily, the AddDetailToAccumulators() adds to the totals...did you ensure that you initialized the totals to zero before you started?
Unless you've changed the code more than outlined...it compiles, but doesn't necessarily work.
Make sure you test it to ensure that it does what it is supposed to.
You still have string sortList;
in main() and it is masking the function you want to call.
You need to pass the number of students to sortlist
Change the call sortList(grades, int size);
into sortList(grades, Num_Students);
I agree with all of Freaky_Chris's suggestions too.
When you add the arrays for counting, what will they contain?
Will they contain the guesses that they have already made?
Will they contain something about the numbers from previous games?
Arrays are generally for a collection of something...what do you want to collect?
One side note, when I was writing the test app, I had to set Num_Students after I read from the input file. My read from the input file looks like the following: (there is some debug still so I can see that it is doing something)
printf("main: reading grades.txt\n");
ifstream infile("grades.txt");
if (!infile.is_open())
printf("main: Failed to open grades.txt\n");
else{
while(!infile.eof() && i < Num_grades){
infile >> grades[i].ID;
infile >> grades[i].q1;
infile >> grades[i].q2;
infile >> grades[i].e1;
infile >> grades[i].e2;
infile >> grades[i].assg1;
infile >> grades[i].assg2;
infile >> grades[i].assg3;
if (! infile.eof()){
cout << "main: grades[" << i << "].ID=" << grades[i].ID << endl;
i++;
}
}
}
infile.close();
Num_Students = i;
Please make any changes from the above that make sense to you.
We need to get your code compiled and running. If you want to work on it some, go ahead. When I first started working with your file, I commented out anything that had a compile error that I couldn't "just fix". Then I started running it and got the functionality that was implemented working. Then I started adding the functionality that I had commented out. (Its an iterative approach to development.)
If you get stuck:
Compile your file.
Post the entire file you just compiled in code=c++ tags
Post the entire error list from that compile in code tags
If you can give me (us) an idea of what you want to use the arrays for, it will help us direct the focus.