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

Maybe its a compiler debugger bug -- I used VC++ 2008 Express and the CLR version displays the values the same way your link shows for the win32 console program.

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

Depends on the compiler -- most c++ compilers will complain about that.

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

OK, cool, thanks for that.

If I wanted to do the same sort of thing with strings but then convert it using c_str() is there a way to add to the c_str() function to do this or would I have to re-allocate etc first before using c_str()?

Ie if I wanted to convert the first 8 characters of the string using c_str() but ignore the last 2 characters, can I instruct it to do this with c_str() or would I have to change the string to get rid of characters 9 and 10 before hand?

I guess you are talking about std::string c++ class and not character arrays.

std::string = "Hello World";
// now cut off the last two characters of the string
string = string.substr(0, string.length()-2);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I. The keyword here is newbie, I think.

LOL! I've almost done that myself a couple of times.

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

Just look at all the programs that are running on your computer. Probably 90% of them are written in C or C++ languages.

>>webdesigning -- C/C++ is not very popular for that. Java and PHP are probably the two most popular languages.

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

>>How would I go about making the second payload exactly the same as the first payload?
You can't without reallocating the entire string because the way the arrays are declared there is no room for expansion.

BTW: neither apayload nor received_payload are null-terminated strings. When you initialize character arrays like that using individual characters the array is nothing more than an array of characters, so you can't use string functions on them such as strlen() to get the number of characters.

>>I am trying this at the moment but it does not work as I guess it is just adding "0" as a character to the array and not terminating that block all together.

Yes, that only replaces the character with 0, it does not change the array size. You will have to reallocate the array if you want to make it smaller. But I don't think its worth the effort. Just put a 0 there and treat it like any other null-terminated string.

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

This would seem to be a good place to begin your research.

iamthwee commented: Here here +15
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I'm sorry but I don't know how to help you. What compiler are you using? Are you using MFC or some other GUI ? What database are you using? How is proto1.exe accessing the database (ODBC or something else)? After running proto1.exe have you check the results in the db from command prompt or some other methodl outside your program?

Can't help you much without seeing code so that we can try the same thing to duplicate your problem.

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

>>when we run the interface and click the button excute the programing code"proto1.exe"
but the result false

Do you mean ShellExecute() return 0? My guess is that you need to add the full path to the proto1.exe program. Example: ShellExecute(this->m_hWnd,"open","c:\\mydir\\proto1.exe","","", SW_SHOW );

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

you are right -- I posted a crappy link. Here is the good link.

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

you need to include string.h header file. And if you are using Microsoft VC++ 2008 Express (or other edition) you may also need to disable 4996 warning number.

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

you can use fscanf("%f", ...) to input the values from the file. Use a counter integer to count 8 fscnaf().

int i;
float nums[8];
FILE* in = fopen("filename.txt");
for(i = 0; i < 8; i++)
{
    fsscanf("%f", &nums[i]);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post your code. We have use that same code thousands of times.

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

yes, but can't help you unless you post the code. Most likely its the way you opened file2. Look at this description of the second parameter. If you want to delete the previous contents of file2 then you have to add the ios::truncate flag in the open() method.

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

Ok, I been playing with the code and I have it calculating and outputting correctly but still has a couple bugs. Whenever I type in an actor like "Al Pacino" with a seperation in the name the program gives me the next 2 questions, however, if I just put "AL" it will ask me the next question correctly, but it messed up when I put a space between actor or film names such as "American History X" but "historyx" would work. What is causing this? here is the updated code

scanf("%s" ...) stops at the first space, so if you want spaces in the text then use fgets() instead

fgets(actorname, sizeof(actorname), stdin);
// now strip the '\n' (Enter key) 
if( actorname[strlen(actorname)-1] == '\n')
    actorname[strlen(actorname)-1] = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

it just seems to make more sense to start from a baseline of the year 1900 instead of the imaginary year 0 because then you're not switching between entire calendar systems.
.

Using imagenary year 0 makes the calculations a little simpler -- If all he wants to do is calculate someone's age it doesn't really matter that the Gregorian calendar wasn't invented until the 16th century.

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

line 37: >> for(j=0; j<n_players; (j++)%n_players) // for each player
That doesn't make sense. what is that mod operator there for?

line 42: deck is undefined

line 42: Withdraw_Card() returns a pointer, so if you want to copy the return value into a non-pointer then you have to dereference it: players[j].hand[k] = *Withdraw_Card(&deck); or this memcpy(&players[j].hand[k], Withdraw_Card(&deck), sizeof(CARD));

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

line 21: you can delete it because the file pointer is already at the beginning of the file when it is opened.

line 26: you don't need the ios::in flag because ifstream is an input stream. All you need is infile.open( filename.c_str()); >>Is there a way to use an array to store the file handles?
Yes. One way to do it is like this:

ifstream* array = new ifstream[num];
...
 for(int i=0; i<num; i++) {
   std::stringstream num_str;
   num_str << i + 1;
   string filename = path + "/dir" + num_str.str() + "/" + file;

   array[i]->open(filename.c_str());

   if(!(array[i])) {
     cout << "opening " << filename << " failed" << endl;
     exit(1);
   }
   else {
     cout << filename << " opened" << endl;
   }
 }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 182 uses stream that is defined in <sstream> header file.

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

We need to see actual code. I suspect the problem is actually somewhere else in your program, quite possibly trashing memory somewhere during the first file read operation, or failing to delete memory when necessary making your program gobble up all the computers resources.

Look at Task Manager while your program is running and see if the memory used by your program or other resources keeps increasing.

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

I don't think *p = new Piece should be any concern because it won't affect Board b; at all.

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

>>A calculator program built using MFC dialog box
You can not use the express version of those compilers to compile that code because those compilers do not support MFC. You have to buy $$$$ one of the other versions of the compiler.

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

My first thought was to use the time functions in time.h standard header file, but the problem with that is that the earliest date that can be use by those functions is 1970, which clearly will not work for your program. So you will have to do the calculations yourself.

If you convert the date to days since year 0 then the calculation of the age will very simple -- just subtract two integers.

For example: I was born February 3, 1943. So converting that to days yields

days from year 0 to 1942 = 709,192 (ignoring leap years)
Number of leap years = 1942/4 = 485
Number of days from 1 Jan 1943 to 2 February 1943 = 31 (Jan) + 2 (Feb) = 33
Now just add all those together yields 709,710

Now do the same thing for today's date (2 July 2008), then subtract 709,710 from that value.

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

just change line 16 to use > instead of < comparison operators.

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

>>I am creating a new sorting algorithm
Not very likely unles you are doing a Ph.D. thesis. Sort algorithms have been one of the most researched topics in computer science, so designing your own unique algorithm is very unlikely.

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

line 30: valar is not a member of CARD. What you want here is value, not valar.

line 32: what is SUIT ? If it is anything other than POD (Plain Old Data) type or an enumeration then the ocmparison on line 32 can't be done like that because you can't compare two structures.

lines 34, 39 and 41. Wrong because card1 and card2 are pointers. But you can do this (see the star) players.biggest_card = *card2;

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

>>BTW can you tell me what type of encoding is being used for the jpg?
Google for "jpg file format" and it will tell you the file format.

>>Now I just need to make an algorithm that encrypts and decrypts the stored data right?
Yes, just like the link I posted, but do that algorithm for every byte.

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

Another hint: check if an antivirus program is running on the computer. If it is, turn it off to see if that fixes the problem. I've seen Norton Antivirus have some problems with some valid programs. Turned off Norton and the problems went away. Of course you want to turn it back on before accessing the web.

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

>>g++-4.2 memJpegDecoder.cpp
That is attempting to compile the *.cpp and create the executable program a.out. From the error message I assume that *.cpp file doesnot contain a main() function, which is required of all c and c++ executable programs.

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

If you want to see the binary value of each byte then you will have to convert the bytes yourself because neither c nor c++ has build-in functions to do that (unfortunately). Here is an example program how to do that. You will probably want to leave the vector as an int vector and convert the data only for display purposes.

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

g++ probably outputs error messages to stderr instead of stdout. try this:

g++ "C:\HelloWorld.cpp" 2> "C:\output.txt"

[edit]Oops! too late. ^^^ is right[/edit]

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

Here is how to monitor file changes in MS-Windows operating systems. You can't do it the way you are trying to.

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

why did unsigned not work and what about the &?

The get() function is only defined for char, not unsigned char. And the parameter is a reference to a char so the & is not useful there.

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

Here is the correction.

char byt;
    while (file.get(byt))
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using MS-Windows and Microsoft compiler then you can find some c++ classes here.

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

I think you need to start at the beginning with a tutorial about std::strings. Here (click this)is one of probably several you can find on the net. Bookmark that link so that you can refer to it often while you work with strings.

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

Any good books specifically for this topic?

Probably not. Just common sense (and experience)

When you say "while (in.get(&byt);
is "in" the name of the file stream?

Yes

So I just need to open a fstream called "in" or whatever and use it that way to read one byte at a time?

Your program already did that. You don't have to change that open line, except remove the ios::ate as I already mentioned.

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

As you must have found out, the exit(0) function exits the entire program, not just the function in which it appears.

It would appear you have the wrong notion about how to return from a function in C or C++

int foo1()
// This function will return the value of an integer
{
    // do something

    // now return the integer
    return 1;
}

// or to exit a function that has no return value
void foo2()
{
    // do something

    return;  // this line is optional.  It can be omitted in void functions
}

int main()
{
     // get the return value from a function that returns an integer, such as foo1()

     int retvalue = foo1();

     // call a void function
     foo2();
}

Its not possible in standarc c++ to capture the <Esc> key. You have to use something nonstandard such as functions in conio.h, if your compiler supports it.

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

line 22: The ios::ate flag does nothing for input files. Its use it intended for output files.

line 19 and 26: memblock should be unsigned char because a binary byte can be any value between 0 and 255.

line 33: can't do that with a binary file. cout expects a string or POD (Plain Old Data). A binary blob is none of those. atoi() takes a const char as a parameter, and a binary blob is not that data type.


line 38: Can't do that either.

line 39: That one's out too. data is a vector of integers and you are attempting to push a char*. Wrong data type.

line 52: Since line 39 is useless so is that loop beginning at line 52.

Ok, so now that I gave you all (or most) of the negatives, how can you improve it? One way is to just simply read the file one byte at a time and add it to the linked list

vector<unsinged char> data;
...
...
unsigned char byt;
while( in.get(&byt) )
{
    data.push_back(byt);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

now that I took line 13 out its giving me about 10 numbers which doesnt make sense

It doesn't make sence because the file doesn't make sense. How is your program supposed to know which line number(s) contains the ItemID ? Your original file format is the most logical, and the format all *.ini files use in the windows operating system. With that format all you have to do is read each line until is contains the string you want.

To continue the code I posted earlier:

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;


int main()
{

   int PlayerID = 1;
   stringstream str;
   str << "[" << PlayerID << "]";
   string player;
   str >> player; // this is now "[1]"

   cout << player << "\n";

   std::string Name;
   int STR;
   ifstream in("Items.txt");
   std::string line;
   // read each line in the file until we find the
   // line that contains "[1]"
   while( getline(in, line) )
   {
        if(line == player)
        {
            //
            getline(in,line);
            // locate the = symbol then extract the remainder
            size_t pos = line.find('=');
            // extract Name
            Name = line.substr(pos+1);

            getline(in,line);
            // locate the = symbol then extract the remainder
            pos = line.find('=');
            // extract STR
            line = line.substr(pos+1);
            STR = atol(line.c_str());
            // now do similar with all the reset of the items

            // Now stop this loop
            break;
        }

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

line 13: delete because it isn't necessary.

line 17: What does the file look like now? Like what you originally posted ? Or did you change it like you said you were. You'll have to post the file so that we can see what the program is supposed to read.

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

1) What kind of project did you create? console, win32 windows, something else?

2) what libraries did you try to link with?

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

As I have said before, getline() takes a std::string as the second parameter and you are passing it an integer. Doesn't work like that. See the example in my post #9 above.

If you just want to read an integers then you can use the stream's >> operator file >> ItemDamagePower;

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

>>Would it be possible to have a program ask you for Item ID
You are posting the wrong question -- that is a YES or NO question. And the answer is Yes.

>>getline which is just for strings right?
Wrong. Everything in a file can be read as strings, both numbers and characters. If you open the file in Notepad.exe all you will see is text. getline() does not distinguish between text and numbers, its all text as far as getline() is concerned.

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

>>how do I go down 1 line read the data and down another read the data and so on?
getline() will do that for you

std::string line;
ifstream in("items.txt");
// find the line is not shown here

// each time the line below is executed the program will read the next line in the file
getline(in, line);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to declare a structure that is each node. If you search for "linked lists" you will get lots of examples, such as this tutorial by Stanford University.

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

The point of the code I posted is to create a string that can be compared to the tag in the file. It can be used like this:

create the string named player as I previously posted
open input file
while not end of file
   read a line
   Is this the same as the player string (e.g. "[1]") ?
   If yes then begin this loop
          read STR
          read DEF
          read SPEED
          read MAGI
          exit both loops
     end of loop
end of while loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've seen similar problems with Windows XP and earlier versions, and the only way I could resolve the problem was to reboot the computer. I'm using Vista Home now and have not had that problem with this version of Windows.

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

There are legatimate uses for such software, for example at help desks there the helper can see that the client is doing so that the helper can help the client. We had software something like that at my last job. I think it was commercial program, possibly Norton PC Anywhere or something like that.