Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Change proc_new_disk_reques() to return a pointer and your program should compile

DiskRequest*  proc_new_disk_request(int procnum, int sectornum, ReadOrWrite rw)
{
	DiskRequest *new_request;
	
    new_request = (DiskRequest *) checked_malloc(sizeof(DiskRequest));
    new_request->dr_procnum = procnum;
    new_request->dr_sectornum = sectornum;
    new_request->dr_rw = rw;
    new_request->dr_next = NULL;
    
    return new_request;
}

Note that at some point in the program that pointer has to be free()'ed.

xyster commented: Amazingly fast reply and so helpful in his reply. Thankyou! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

tux> If your computer has more than a GB of RAM that wouldn't be a problem

But the OPs computer crashed with just a megabyte-sized array. :( So it's not about total space available, but about how much stack space is reserved (which of course can be increased with a compiler option).

You are right. My computer has 8 gig RAM, compiled with VC++ 2008 Express, and it crashed when I ran it.

booker commented: GRATE KNOWLEDGE +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

um, hello??

Howdy :)

Nick Evan commented: Hi! +16
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To be fair, it doesn't really matter whether he wrote all that code or not. He never said he wrote it.

IMHO he has jumped off the deep end of the swimming pool before he has learned to walk. My suggestion is to put this program aside for awhile and learn the basic of programming. After a few months' studying and learning you might be ready to tackle this program again.

jephthah commented: werd, dawg. thats what i was sayin' yo. :P +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Salem commented: It'll do +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in main.cpp, delete line 2 #include "hello.cpp". NEVER EVER include a *.c or *.cpp file in another one like that. If main.cpp needs to know about that function, then just use extern keyword, like this:

#include <iostream>
using namespace std;

extern int funny_words();
// blabla

Also, funny_words() is declared to return an integer. You must add code to do that on line 16. If you don't need it to return anything then change it to void function void funny_words()

Salem commented: You should have mentioned the "#define GEQUAL" horror as well :) +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After allocating the memory for the array you can not increment or decrement the pointer. When you do, you destroy the memory that was allocated because the pointer to the original memory is lost.

If you want to increment/decrement pointers, then create another pointer for that purpose, but leave the original pointer unchanged.

tux4life commented: I can't explain this in a better way :) ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I am new to programming, what does this code actually do? Where would I put it?
You are trying too hard. It's a lot simpler than what you posted.

Every character has an ascii value associated with it. See an ascii chart for the values. Internally, a C or C++ program does not know a thing about the letters 'A', 'B', etc. only numeric ascii values shown in that chart. When you type 'A' with your keyboard you are really seeing the ascii numeric value converted to a graphic that is displayed in the font you have selected. That's why an 'A' may look differently with each font you choose. Behinds the scens an 'A' is 65 regardless of the font.

You will understand this better if you write a short program that displays all the characters of the alphabet.

#include <iostream>
using namespace std;

int main()
{
    for(char i = 'A'; i < 'Z'; i++)
    {
        cout << i << " = " << (int)i << "\n";
    }
    for(char i = 'a'; i < 'z'; i++)
    {
        cout << i << " = " << (int)i << "\n";
    }
}

For the purpose of your assignment, just prompt for two characters then display their ascii values as illustrated in the above program. It's really no more difficult than that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

config files have a general format as <tab name>=<value> What that program is doing is finding specific tag names and, if found, reading the value field.

Line 26 is a loop that reads all the lines in the file. Then 28-35 check for specific tag name and, when found, reads the value field of the line.

If you are still confused then compile the program for debug and use your compiler's debugger to single step through the program, then inspect the value of the variables to see what the program did.

kelechi96 commented: Thank You +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first parameter must be either a static method of a class or a global function. You can't pass class methods unless they are declared static.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Does variables in a namespace behaves like a static variable where it will keep the most recent value?

No. static variable may appear either inside a class or outside any class.

  • When static variables are part of a class then they require class scoping, such as MyClass::MyVariable = 0; They must also be declared globally just like any other global variable with the class scope just as in the previous example.
  • When static variables are declared globally (not inside a class) then they are in global namespace unless you put a namespace around them.
namespace mynamespace
{
    int MyGlobal = 0;
}

Functions and methods can also be declared static.

tux4life commented: I let that question open for you :P +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to pass the string by reference. in GetArray() the string is local to the function so when the function returns the string is destroyed, invalidating the return pointer. const char* getArray(string& s){ Actually the function doesn't need the temp pointer at all.

const char* getArray(string& s)
{
    return s.c_str();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After line 19 you need to flush the input buffer of the '\n' character. cin.ignore(1000,'\n'); should do the trick.

hurbano commented: very helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i had a problem a little while ago, just assumed you were working on the servers. Didn't last more than 5-10 minutes.

nav33n commented: Even I assumed the same :) +11
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

doesn't matter why -- gets() is a horrible function anyway. Use fgets() instead of gets(). And if you really want the source code for that standard C function then download the gnu compiler source code.

Salem commented: Agreed, but the source for gets() et al will be in libc, not the compiler itself +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hmm, in trying that, I discovered this:
but instead I see nothing! Why would that be? I was also seeing nothing with the \r, but I bet it's the same reason.

Thanks,
Dave

You wrote the wrong test program. Assuming you are writing this under MS-Windows os. If *nix then delete windows.h and replace Sleep() with sleep().

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    int counter;
	for(counter = 1000; counter < 10000; counter++)
	{
		cout << "\rhi " << counter; cout.flush();
		Sleep(250); // 1/4 second sleep
	}
    cout << "\ncounter = " << counter << "\n";
return 0;
}
daviddoria commented: Ancient Dragon has all the answers! +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its not possible to write to an executable file while it is executing -- the operating system will forbid it.

tux4life commented: That was an answer right to the point ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it <posts per day> could be figured out by doing the simple division yourself) .

Its not that trivial. For instance, my join date was Aug 25, 2005. So, how would you calculate my posts/day without first calculating the number of days between my join date and today? It would be a lot better to just let the computer do what computers do best and calculate the posts per day for us. I don't see why it would be so hard to put it between Posts and Blog Entries on the profile page.

verruckt24 commented: Exactly - Also I would be eager to know how many people actually do the so called trivial calculation. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The general method of using multiple *.c files is to put the function prototypes in a header file, then include that header file in all the *.c files that need the functions. If you look at a couple standard C header file that are supplied by your compiler you will see that they only contain #defines, typedefs, and function prototypes.

Here is a simple, brief example. You need to compile both *.c programs then link the two object files in order to get the executable program. Exactly how to do that depends on the compiler you are using.

// foo.h
extern void foo();
// foo.c
#include <stdio.h>
#include "foo.h"

void foo()
{
   printf("Hello World\n");
}
// main.c
#include "foo.h"
int main()
{
    foo();
}
tux4life commented: Nice explanation ! +1
Salem commented: Good job +29
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It doesn't compile because it is missing { on line 3, not because of the // comments. Compiles fine with *.c file extension on vc++ 2008 express.

void f();
int main() //
{ // <<<<<<<<<<<<<<<<<<<<<<<<<<<
    f();
    return 0;
}
jephthah commented: i love when that happens :) ... except of course when it happens to me :( +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

closed

Moschops commented: Incisive and witty. +9
markwiering commented: Why? Now we can't react anymore! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The reason it closes is because cin left the Enter key '\n' in the keyboard buffer, and the next cin.get() just removed it. To fix this problem you need to flush the keyboard buffer after entering numeric data. One way to do that is call ignore(). See Narue's article in the c++ forum stick post about details of how to flush the input keyboard buffer.

cin >> price;
cin.ignore(); // flush '\n'
Intrade commented: It's nice to know you're still at it, helping people =) +1
tux4life commented: Very well explained ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

just use two (or more) case statements with no break in between

switch(keycode){
    case DOWN :
    case TAB:
                    if(edtIndex == editSize - 1){
                         fieldPos = edtList[0];
                         edtIndex = 0;
                    }
                    else if(edtIndex < editSize - 1)
                         fieldPos = edtList[++edtIndex];
                    break;
          }
sid78669 commented: Marvelous!! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
NicAx64 commented: Thanks man , now i can type the question directly nica tool , need to find a exe or mozilla addon of that web application. Or somebody write a extension +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Comatose commented: That's How I'd Roll! +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thread closed.

nav33n commented: I am glad you closed it :) +10
Ezzaral commented: Good call. +19
Comatose commented: Taste It! +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

julienne is a nice name by the way, i will name my daughter like that if i have one oneday

Enough of this Narue (Julienne) fasination -- had you posted like this several years ago when she first joined DaniWeb she would have ripped your throat out :)

Nick Evan commented: *nods* +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

integer digits are also characters. For example '0', '1', '2', ... '9' are all ascii characters just as 'a', 'b', ... 'z' are ascii characters.

Its quite easy to convert an ascii numeric character to an integer -- just subtract '0'

int x = '0' - '0'; // result is 0
x = '1' - '0'; // result is 1
...

Why does that work? Look at any standard ascii chart and you will see that every character in the ascii chart has a numeric equivalent. When you code x = '1' - '0' the compiler looks up those charcters in the ascii chart and converts them to their numeric equivalents x = 49 - 48;

lllllIllIlllI commented: nice +1
tux4life commented: nice, didn't know it was possible ... very useful post ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In addition to what Ancient already mentioned:
Change #include "windows.h" to #include <windows.h>

It really doesn't matter with that compiler.

Nick Evan commented: Didn't know that +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are you using? It compiled and linked ok using VC++ 2008 Express.

You can't use iostream.h and using namespace std; at the same time.

tux4life commented: Useful post, I did already know it myself, but maybe the others didn't ... +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you probably don't need to see an expensive head shrink. And many married people also go around violating every rule of their religion -- assuming they have a religion.

Married people don't hate single people, many married people are jealous because they'd like to be single again. But that's their problem, not yours.

nav33n commented: Ah! Now thats the truth! ;) +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

closed

Nick Evan commented: thanks +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Happygeek has devised a secret mathematical formula which determines the next member of the month

Its called "toss of the coin" :)

verruckt24 commented: Like it +3
nav33n commented: Heh! I think you are right.. +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The do loop is incorrect. See correction below. Same problem with getMinutes().

void getHours (int& input1, string& s)
{
	bool result;
	do {
	cout << s;
	cin >> input1;
	result = isValidHours(input1);
	} while (result == false);
}
anbuninja commented: b/c you always help me out :D +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

All you have to do is put that code in a loop. Simple.

for(i = 0; i < 10; i++)
{
if( score[i]>79 && score[i]<101 ) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl;
} else if( score[i]>74 && score[i]<80) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl;
} else if (score[i]>69 && score[i]<75) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl;
} else if( score[i]>64 && score[i]<70) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB"<<endl;
} else if (score[i]>59 && score[i]<65) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB-"<<endl;
} else if( score[i]>54 && score[i]<60) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC+"<<endl;
} else if (score[i]>49 && score[i]<55) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC"<<endl;
} else if( score[i]>44 && score[i]<50) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC-"<<endl;
} else if (score[i]>39 && score[i]<45) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tD+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tD+"<<endl;
} else if (score[i]>34 && score[i]<40) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tD"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tD"<<endl;
} else {
  cout<<i+1<<"\t"<<score[i]<<"\t\tF"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tF"<<endl;
}

}
ARYT commented: "do-while"??? :( +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how to do that will depend on the compiler, each one is a little different.

Do you mean you want to put the source files, such as *.cpp, *.c, and *.h, in different folders?

dvsConcept commented: very helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here is the output I got

1         George Washington          Fed   	4/30/1789	3/3/1797	2/22/1732	VA		12/14/1799	VA		1
2         John Adams                 Fed   	3/4/1797	3/3/1801	10/30/1735	MA		7/4/1826	MA		1
3         Thomas Jefferson           D/R   	3/4/1801	3/3/1809	4/13/1743	VA		7/4/1826	VA		1
4         James Madison              D/R   	3/4/1809	3/3/1817	3/16/1751	VA		6/28/1836	VA		1
5         James Monroe               D/R   	3/4/1817	3/3/1825	4/28/1758	VA		7/4/1831	VA		1
6         John Quincy Adams          D/R   	3/4/1825	3/3/1829	7/11/1767	MA		2/23/1848	MA		1
7         Andrew Jackson             Dem   	3/4/1829	3/3/1837	3/15/1767	SC		6/8/1845	TN		1
8         Martin Van Buren           Dem   	3/4/1837	3/3/1841	12/5/1782	NY		7/24/1862	NY		1
9         William Henry Harrison     Whig  	3/4/1841	4/4/1841	2/9/1773	VA		4/4/1841	OH		1
10        John Tyler                 Whig  	4/6/1841	3/3/1845	3/29/1790	VA		1/18/1862	VA		1
11        James K Polk               Dem   	3/4/1845	3/3/1849	11/2/1795	NC		6/15/1849	TN		1
12        Zachary Taylor             Whig  	3/5/1849	7/9/1850	11/24/1784	VA		7/9/1850	KY		1
13        Millard Fillmore           Whig  	7/10/1850	3/3/1853	1/7/1800	NY		3/8/1874	NY		1
14        Franklin Pierce            Dem   	3/4/1853	3/3/1857	11/23/1804	NH		10/8/1869	NH		1
15        James Buchanan             Dem   	3/4/1857	3/3/1861	4/23/1791	PA		6/1/1868	PA		0
16        Abraham Lincoln            Rep   	3/4/1861	4/15/1865	2/12/1809	KY		4/15/1865	IL		1
17        Andrew Johnson             Dem   	4/15/1865	3/3/1869	12/29/1808	NC		7/31/1875	TN		1
18        Ulysses S Grant            Rep   	3/4/1869	3/3/1877	4/27/1822	OH		7/23/1885	NY		1
19        Rutherford B Hayes         Rep   	3/4/1877	3/3/1881	10/4/1822	OH		1/17/1893	OH		1
20        James A Garfield           Rep   	3/4/1881	9/19/1881	11/19/1831	OH		9/19/1881	OH		1
21        Chester A Arthur           Rep   	9/19/1881	3/3/1885	10/5/1829	VT		11/18/1886	NY		1
22        Grover Cleveland           Dem …
rickster11 commented: Thanks, helped a bunch +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

your loop is doing too much work.

char codes[] = "qwertyuiop";

string dCode = "wtu";  // hard-code search value

for(int i = 0; i < dCode.size(); i++)
{
    for(int j = 0;  codes[j] != 0; j++)
    {
          if( dCode[i] == codes[j])
          {
              cout << codes[j-1];
              break;
          }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You could start here

Microsoft publishes such a book in several volumes, last time I looked at my local book store it cost over $150.00 USD for the set.

And your term "most useful functions" depends on who wants the information. "Most useful" to me might not be the same as "most useful" to you.

When I want a certain win32 api function I just google for it, or search for it at www.microsoft.com.

Comatose commented: *Falls Out Of His Chair Laughing* +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

> The first time that January 1 will fall on a Sunday is the year 4300.

Oh wait, don't you have an official holiday on 1st January? ;-)

And you don't ??? Bummer!

~s.o.s~ commented: Yes, at least Software Engineers here do have a day off on 1st. :-) +26
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> X newX = new X();
wrong syntax. should be X* newX = new X;

Comatose commented: Great Minds +10
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>while (tokenPtr!='NULL')

Remove the quotes around NULL. while (tokenPtr!=NULL) >>char checkCount[20];
You should make that a lot bigger. A 20 character sentence is pretty darned short.

Dontais commented: Great help, thanks Ancient Dragon +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10 is wrong. Why is value a pointer? From the class constructure it appears to be just a single integer, and you don't need a pointer for that

And get rid of those stars on line 10.

class box{
public:
         int value;
         box()
         {
                   value=0;
          };
          box(box &c)
          {value=c.value;};
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Freeky -- again, that code requires the use to hit the Enter key

Nishinoran: since your program is already using kbhit() when the program returns to the place to begin getting keys from the keyboard you can flush all the keys with another loop using kbhit

while( kbhit() )
   getche(); // get the key and toss it into the wind
Falkoner1 commented: FRIGGIN EPIC! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I commented out the queue.cpp include and associated objects, leaving only the file reading. Your problem is NOT in file reading because that works ok. That means the problem is in the code you did not post.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) your implementation file is missing the class constructor implementation.

2) your class is missing a default constructor as required by the assignment # 2a.

3) Post the attempts you have made to write main() and test the various functions. I would suggest you write a menu something like this:

1.  Create a new account
2.  Deposit
3.  Withdraw
4.  Show Balance
5.  Quit
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Comatose commented: Hahahaha :) +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>What ink is used to print dollar
Green.

Nick Evan commented: best answer :) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I found this when googling for the lyracs of Bob Hope thream song. Posting it here because I enjoyed this video and thought you might too.

http://www.youtube.com/watch?v=xWHf_vYZzQ8

Gerryx1 commented: A worthwhile watch, good musuc, funny. +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I hope all of you Obama fanboys are proud that you finally elected your closet terrorist into office so that he could shut down Gauntanamo Bay and release all his muslim friends, and while he was at it he shut down all over seas prisons linked through the CIA so that we no longer have any control over who attacks our country.

You are welcome. :)

I don't know if any of you obama people realized that not once after 9/11 was the US struck by terrorism since Bush put his foot down and did somthing about it.

Nobody said otherwise, so you are just mouthing off to mouth off.

But anyways, y'all can go hug a tree somewhere else and cry about peace on your own time.

Go cry somewhere else. We don't need crybabies.

Congradulations on destroying America from the inside as we know it. Ill be moving to Canada now... laters

Great News :) :) Don't let the door hit you in the ass as you leave.

Ezzaral commented: I endorse this message :) +16