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

If the file contains several lines as you described then after getline() you can use stringstream to divide it up into individual integers. Also note the difference in the while statement -- using eof() like that doesn't work.

#include <sstream>
<snip>
string line;
ifstream myfile("input.txt");
if(myfile.is_open()){
    while(getline(myfile, line) )
          cout << line << "\n";
          int value;
          stringstream str(line);
          while( str >> value)
              cout << value << "\n";             
    }//while
    myfile.close();		
}//if
    else cout << "Unable to open file" << endl;

>>I was wondering if there is a string tokenizer function for c++ such as the one from Java
I dont' think so.

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

>character character;
That only instantiates an instance of the structure -- it doesn't initialize it. There are at least two ways to initilize it:
1) in c++ you can add a constructor that initializes structure members

2) set members to something at the time of instantiation: character character = {0,0,0 <etc for each member>}; 3) set each member after construction

character character;
character.member = 0;
// etc for each structure member

The function experience() won't work correctly anyway even when you do correct the above problem. You need to pass the structure into that function as a parameter int experience(character& chr) And don't name the object the same as the data type because it gets confusing. Give the data object a different name something like I posted in the previous code snippet.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
const int row= 12,seat= 5;
char plane[row][seat];

this is wrong. you cant use variables to declare the size of an array like that. try:

char plane[12][5];

you can then *access* the array using variables, like youre doing with the "y" as row, and "x" as seat.

i think you're on the right track.

Sorry, but he did it the correct way. Declared const variables is completly correct. You would have been right had he not used the const keyword.

jephthah commented: um, well, yeah.... oh, look, the queen! +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

add a new line between lines 10 and 11 that displays the row number.

lines 10 and 11: Reformat the code so that you can easily read it. Your formatting style is terrible. There is an example of how it should look

for (y=0;y<=12;y++)
{
    for(x=0;x<=5;x++)
    {
          plane[y][x]='*';
          cout<<plane[y][x]<<"\t";
    }
    cout<<endl;
}

[edit]Also, where are all the other functions that are in the requirements for your program ?[/edit]

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

First call GetSelectedCount() to get the number of selected items, then in a loop call GetNextItem() to get the index value of each selected row. See example here.

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

If you compiled the pdcurses win32 libraryt and demo program, the demo file newdemo.c contains the following code that appears to be doing what you want.

int WaitForUser(void)
{
	chtype ch;

	nodelay(stdscr, TRUE);
	halfdelay(50);

	ch = getch();

	nodelay(stdscr, FALSE);
	nocbreak();		/* Reset the halfdelay() value */
	cbreak();

	return (ch == '\033') ? ch : 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The President of the USA is an fraightening job because it is physically and mentally exhausting. Every president ages about 8 (or more) years during his 4-year term. I doubt there is a more difficult job in the world than the job of being the President of USA.

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

I wonder if Isonis got his computer fixed or replaced.

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

using the curses library would probably be the most portable way to do it. Check ncurses for *nix and pdcurses for MS-Windows. If you are not concerned about portability and using an MS-Windows compiler then your compiler MIGHT support the functions in conio.h -- mainly _kbhit().

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

Ed: you read AD's post before AD deleted it. AD doesn't know a hill of beans about managed code.

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

you need to do that via sockets. There are quite a few tutorials.

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

Agree with Ed and Nick -- %p will display the address in hex values, while %u will display it as an unsigned integer. Which one to use really depends only on how you want to view the address. IMO hex is preferable.

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

>>Account = Account + 100;
If Account is a pointer, then that line is attempting add 100 to the pointer. I doubt that is your intent. We can't tell from your post what exactly you want that line to do.

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

We have an IRC Chat Network button located on the right side of any DaniWeb window. You can chat with people here on DaniWeb.

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

[SOLO] FunctiongetData:Thisfunctionreadsandstoresdatainthetwodimensionalarray.
b. FunctionaverageHigh:Thisfunctioncalculatesandreturnstheaveragehightemperaturefortheyear.c. FunctionaverageHigh:Thisfunctioncalculatesandreturnstheaveragelowtemperaturefortheyear.d. FunctionindexHighTemp:Thisfunctionreturnstheindexofthehighesthightemperatureinthearray.
e.
FunctionindexLowTemp:thisfunctionreturnstheindexofthelowestlowtemperatureinthearray.(These functions must all have the appropriate parameters.)

Difficult to believe that any college professor would actually give you instructions that look like that :icon_eek: Where are the spaces between words :?:

>>will it output juct like this??
No -- Its just simple code so illustrate how to use the arrays.

Start out by creating a program with just the functions that your instructor wants. Get that working and compiling without error. Then start filling in the functions one at a time. Do a function, or a few lines of code, compile until there are no errors, then code a little more.

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

No one can really help you with the little amount of info you posted. Post parts of the file so we can see what it contains.

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

I had the same problem with Dev-C++ when I first got Vista. Searched Bloodshed's forums and found that the compiler does have a few problems with paths on Vista. Go to Tools --> Compiler Options, click the Directories tab, then manually expand the paths you find there to contain the full path to all files. Then click the Programs tab and do the same thing.

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

I can't help you with your problem, but you don't need that while loop f_in.read(speech, 10000 * sizeof(short)); But of course there is no guarentee that sizeof(short) will be 2. It might be on your system but if you intend to port that porgram to another os then the size may be something else.

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

how can i make array on a function>????

Do you know what a two-dimensional array is? Do you know anything at all about arrays?

int main()
{
     int array[5][2]; // this is a 2 dimensional array

}

If you are having problems with the concepts of arrays then you need to go back and restudy the material in your textbook. Do the problems at end-of-chapters until you get the concepts straight in your head.

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

Just search the PATH environment variable for it. In MS-Windows you can do it like this

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

bool search(string path)
{
    WIN32_FIND_DATA data;
    path += "\\gdiplus.dll";
    HANDLE hFind = FindFirstFile(path.c_str(), &data);
    if(hFind != INVALID_HANDLE_VALUE)
    {
        FindClose(hFind);
        return true;
    }
    return false;
}

int main()
{
    char *buf = 0;
    size_t len = 0;
    errno_t err = _dupenv_s(&buf, &len, "PATH");
    if(err == -1)
    {
        cout << "Error getting PATH\n";
        return 1;
    }
    stringstream str(buf);
    string path;
    while( getline(str,path,';') )
    {
        if( search(path) )
        {
            cout << "Found at: \"" << path << "\"\n";
            break;
        }
    }
    free(buf);

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

Not sure just what you are asking Do you want the contents of the array name to contain some text that the user entered via keyboard ?

char name[80] = {0};
printf("Enter your name\n");
fgets(name,sizeof(name), stdin);
printf("You entered %s\n", name);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>lpBufferA [dwSize] = '\0'; // Terminate headers with null.
Error probably here. The value of dwSize is still MAX_PATH at that point.

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

Welcome to DaniWeb

>>Yes, I do really sit on the beach with a laptop and GPRS connection uploading code to a web server in some distant land

:* :*:* You must have everyone's dream job

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

Welcome to DaniWeb. I don't know the first thing about PHP but there are several other experts here that can help with your questions -- or you can help others with their problems.

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

Welcome to DaniWeb, John. Hope to see you around.

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

Thank you very much! I did get some spams these days, but now I don't know how to modify what I have submitted?

You can't, but I can (and did)

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

>>It is unfortunate that boomers and seniors can't earn extra monies for themselves
Depending on what country you live in maybe for you, but not for me. In USA there are lots of part time jobs out there that we can do. Won't make a fortune, but will earn enough to enjoy my senior years. I work part time at Wal-Mart but right now with summer vacations I'm getting more hours than I really want.

If you are not a senior and are talking about someone else, then what you can do is spend more time with someone you love. Your time is more precious to seniors then your money.

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

A callback is just a function that you write that will be called by the driver. When initializing the driver function you pass it a pointer to your function. You will have to read the ASIO Auto Driver's programming manual to find out exactly how to code the callback function.

// in the driver code
int inidriver( int *(callback)( <parameters here> ) )
{
   // blabla
}

// your code
int myfn( <parameters here> )
{
   // do something
}

int main()
{
    inidriver( myfn );
    <other stuff here>
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what container are you using? vector? Yes, then treat a vector just as you would a simple array of ints. If you can do this this an array of ints then you can do it with a vector -- same syntax.

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

>>how to solve this problem so server gets output individually for client??
Each client needs to use different ports. You can reserve a range of ports in the hosts file on the server computer so that nothing else on the server will take them. Assign port no 8000 to client #1, port 8001 to client #2, etc. Then in server side when recvfrom() gets something from client, server kicks off a thread to process the info so that the server can go back to recvfrom() without blocking.

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

I think I know what you want -- if I'm in the second room, save, quit, then resume the program should resume on the second room. Right?? If yes, then I think you need to save another piece of info in save.txt -- what room number the game is in.

Then in mainMenu()

case 'c':
        case 'C':
               continueGame(); // goes to void continue
               if(CurrentRoom == 2)
               {
                   roomtwo[m][n] = guy;
                   newRoom();
                   room2();
               }
//               else if(CurrentRoom == 3)
//                   room3();
            
            menuLoop = 0;
            break;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably because there are a lot of compile errors. Add #include <string> What compiler are you using. I used VC++ 2008 Express and it identified a bunch of errors.

AmasiVillage: contains a recursive function call which will cause a runtime stack overflow. Maybe you meant to do this:

if (choice == 7)
        {
            SaveGame();
            AmasiVillage();
        }

Same problem in function Reya()

Function CharacterOptions() was never coded.

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

To my knowledge there is no way to get the filename once the bitmap has been read into memory. Actually, the bitmap may not be in any file at all, but can be part of the program's resources, which is attached to the end of the executable program.

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

what have you tried ? Please post your attempt to do this homework assignment. One way to solve the problem is to use the macro tolower() that's in stdlib.h ch = tolower(ch);

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

Attached is the revised code that works. It only generates one file named save.txt. You should consolidate all those instance of using ofstream because in my code they all do the same thing.

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

>>Triangle tri (3,4); //looks like a drifting object
That is not a reference. Its just simply instantiating a Triangle object and passing the two parameters to the constructor. No references involved here.

If that's true, can I do something like--

Point myPoints[3] (2, 2);

or maybe

Point myPoints[3] = (2, 2);
--where all of the points are initialized to be (2, 2)?

Unfortunately you can't to that.


>>One last thing! When would I ever use a reference to a pointer? i.e...
When you want a function to allocate memory for the calling function's pointer

int foo((int *&p)
{
    p = new int[255];
    for(int i = 0; i < 255; i++)
       p[i] = i;
}

int main()
{
    int* p = 0; // a null pointer
    foo(p);
    for(int i = 0; i < 255; i++)
       p[i] = i;
}

The above can also be done with pointers, but references is a lot cleaner and less complicated

#include <iostream>
#include <ctime>
using std::cout;

void foo(int **p, int n)
{
    *p = new int[n];
    for(int i = 0; i < n; i++)
    {
        (*p)[i] = rand();
    }
}

int main()
{
    int* p = 0; // a null pointer
    int n = 25;
    srand((unsigned int) time(0) );
    foo(&p, n);
    for(int i = 0; i < n; i++)
       cout << p[i] << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm 75% certain that I will vote for Obama. I don't want someone who is 7 years older than I am to be President. He needs to be in a nursing home, not the white house. Even French President Charic was only 62 when he was first elected as president.

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

>>Why use the stack of the space is so limited?
What makes you think stack space is so limited ? In MS-DOS 6.x and earlier and in some embedded systems that is true, but if you are using *nix or MS-Windows 32-bit compilers stack space isn't really anything to be too concerned about unless you have an object that used several megs of space.


>>What are the advantages to using the stack over the heap?
As I mentioned in your other thread, using pointers unnecessarily can be dangerous to your program. Coders (me too) have spent days trying to find a bug with pointers. Such bugs are often very difficult to find.

>>Is it really so bad to use pointers vs "reference variables?"
No -- but as you found out you have to be very very careful. You can introduce all sorts of memory leaks and bad pointers when you use a lot of pointers. You can easily avoid all those nasty problems by using references.

>>What exactly is the life of a stack object?
The life of a stack object is the life of the function in which the object is declared. All objects are destroyed as part of the function exit code. Memory dynamically allocated to pointers are not auto destroyed, you have to explicitly use the delete operator if new was used to allocate the memory. So if the function returns without deleting the pointer then a memory …

William Hemsworth commented: Better than my answer :p +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

suggestion: change the color of the help menu because it can't be read. Dark blue on black background is nearly impossible to read.

Why don't you just save the coordinates for all rooms then read all of them.

ifstream continueData;
continueData.open("save.txt");
continueData >> playerName >> life >> x >> y >> m >> n;
continueData.close();

<snip>
             ofstream saveGame;
             saveGame.open("save.txt");
             saveGame << playerName << " " << life << " " << x << " " << y;
             saveGame << m << " " << n << endl;
             saveGame.close();
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>is there a way to limit/set its size to a value
No. But if passing it to some other function you can declare it as const so that is can not be changed.

See std::string methods here

To get all substrings

std::string str = "one two three one two three";
while( (pos = str.find("two")) != string::npos)
     string str1 = str.substr(pos,pos+2);
     str = str.substring(pos+2);
    cout << str1 << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And remember that most professionals didn't go to school to learn to program, they taught themselves or were taught on the job.

That was my case too. I didn't start learning until later in my life, over 40. I bought a cheap C compiler, a book, and started studying. Then I got an entry-level temp job at Account Temps and my career took off from there.

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

If you use MFC you can use a Splitter Window and Tree Control. I'm sure you can do it without MFC but it will be a whopping lots of work and code. And of course to use MFC you will have to use a Microsoft compiler (not the free Express editions) because Dev-C++ doesn't support it.

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

Creating a grid control is a very complex task. Here is one free control that I have used in the past and consists of thousands of line of code.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <"windows.h">
#include <"iostream">

Do not use both angle brackets and quotes. One or the other. Use angle brackets for your compiler's header files and quotes for the header files that you create.

#include <windows.h>
#include <iostream>

After a successful compile you will get errors about undefined references to OldInitialize() and OleUnitialize(). You have to include libole32.a in the linker commands. So far I have not been able to get that compiler to successfully link the program.

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

>>array= 0 + rand() % 100;
That will not produce a random number between 1 and 100. Instead it produces a number between 0 and 99 inclusively. The instructions say nothing about generating 200 UNIQUE random numbers so I guess adding duplicate numbers to the array is not a problem.

As for the rest of the program I think you mis interpreted the instructions -- you have to use a loop something like this:

do this 100 times
    generate a random number between 1 and 100
    search the array for the number
    is it found ?
        yes, then increment success counter
    go back to top of loop
end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

He could post the same thing in Job Offers without getting flamed or getting his phone number snipped.

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

>>To tell you the truth I was purposely trying to use pointers since they're very adjacent to Java's reference variables
I think you misunderstood the relationship. From what I understand Java doesn't have the concept of a pointer like what is in c++ pointers. The reference variables in Java are equivilant to the referneces in C++, not pointers. See line 45 of the code I posted.

>>I didn't realize they could cause so many problems!
Yup -- try to avoid pointers when ever possible.

>>I expected it to be more efficient to use a structure
No. In C++ structures are nearly identical to classes. There is no efficiency difference between the two.


>>I didn't think I was using too much space honestly.
It wasn't the space but the complexity of pointers. You just simply made your program too complex with all those pointers. And I didn't test all the pointers but it is pretty easy to use uninitialized pointers or pointers with NULL values. And either of those conditions will cause the program to scribble all over memory.

The fewer pointers you use the fewer bugs you have to debug.

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

The binary flag prevents streams from interpreting any of the binary characters (whose character values outside the range of normal printable characters). In normal text files the "\r\n" characters (ms-windows) in the file are used to indicate end-of-line for functions such as getline(). Binary files may also by coincidence have the "\r\n" pair, so the binary flag is used to prevent any interpretion by fstream.

>>and other flags like ios::app are used instead
You can use both flags at the same time by using the or operator | to combine them ofstream out("test.data", ios::binary | ios::app);

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

The problem(s) appear to be the use of all those pointers. Get rid of all the pointers and you get rid of the errors. Here's the revised program without pointers. This implementation also deleted the destructors, new and delete operators.

#include <cstdlib>
#include <iostream>
#include <math.h>

/**
File test_!.cpp in Project testing_Something.dev

Progress of project: Unexpected System exit after a certain amount of time, but no errors.
Suspecting the stack ran out of room to store variables for vector-magnitude comparisons via
the overloaded operator ==.

So far tests show that this project was successful, but I'm still trying to find the error.
*/

using namespace std;

class Point;
class Triangle;
class P2DVector;

class Point{     
      private:
             double xP;
             double yP;
             
      public:
             Point(double x, double y){
                   xP = x;
                   yP = y;
             };
             Point() {xP = 0; yP = 0;}
             void Set(double x,double y) {xP = x; yP = y;}
             double getX(){return xP;};
             double getY(){return yP;};
             void showCoord(){
                  cout << getX() << ", " << getY() << endl;
             };
};

class P2DVector{
      private:
             Point points[2]; 
      
      public:
             P2DVector(Point& first, Point& second){
                      points[0] = first;
                      points[1] = second;        
             };
             P2DVector() {points[0] = Point(0,0); points[1] = Point(0,0); }
             void Set(Point& first, Point& second){
                      points[0] = first;
                      points[1] = second;        
             };
             //~P2DVector(){for(int i = 0; i < 2; i++){ if(points[i] != 0){delete points[i]; points[i] = 0;}}}; 
             static double power(double value, int exponent){
                    if(exponent < 0)
                    {
                        cout << "Negative powers currently unsupported.";
                        cout << "\nRetrying with positive value." << endl;
                        return power(value, -exponent);
                    }
                    else …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why dont you just continue to use the make file to rebuild your changes? seems like less work to me.

Some programmers write libraries for several different compilers and operating systems. I don't know but possibly this is the case here.