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

Before jumping off the deep end of the pond you first have to learn to swim. read some tutorials about loops and all will become clear to you. Remember, google is your friend.

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

on line 21 you need to look up the username in a database and, if found, verify the password.

Put lines 10 thru 21 in a loop so that the program can start all over again if the username and/or password are incorrect (not found in the database)

Note that the database can be as simple as a text file or as complicated as an SQL Server. How you do that part is up to you to decide when you design your program.

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

i have pyschological problems guys,

Oh so now you think we are your phyciatrist? Sounds like you are making a career as a student. Hurry up and get your degree before you die of old age :)

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

Isn't cheating exactly the cause of our global financial crises were are now in? Whats-His-Name started a pyramid scheme that cheated thousands of people out of several Billion dollars? I read an article in local newspaper about a woman in Missouri who did a similar thing but on a much smaller thing to the farmers in Missouri.

If you teach students that cheating is ok in college, then why not extend that concept to cheating in the business world?

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

you have to create one big string that includes all the variables

#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string ip
string command;
cout << Enter an ip;
cin >> ip;
command = "ping " + ip;
system(command.c_str()); //// this is the problem. how do i enter the value of "ip" here?


    system("PAUSE");
    return EXIT_SUCCESS;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You put the guards in the *.h files that you wrote, not the STL or other system files. If you are getting errors, then you didn't do it correctly, and you should post the header file w/guards so we can see what you did.

//"xmlParser.h"
#ifndef XMLPARSER_H
#define XMLPARSER_H
// stuff goes here

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

The reason your file is 8 time bigger is because you are forgetting that each bit (in this format) represents a pixel. You are reading (and writing) 1152 * 813 bytes, but that is actually how many bits you should be reading! There will probably be some padding at the end of the picture rows, so there will be more than 1152 * 813 / 8 bytes. You will have to look up the info for the padding. You could try assuming that it's simply to the nearest byte and see if that works, but it could be rounded off to 4 bytes. At any rate, that's your basic problem.

Yes I think you might be right about that because that is just about the number of bytes my version of the program actually read.

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

After some testing with the code you just posted I found that the file marbles.pbm does not contain enough data --

Here is the output of my version of the read function:

Error reading bin file
Expecting 936576 bytes but found only 117071 bytes.

and the code I changed

void CarregaPNM::LoadPixels(){
<snip>
	else if( MV[1] == '4' ){//if is a bin pixel map (PBM P4)
        long max = width*height;
        long i;
        unsigned char* buf = new unsigned char[max];
        readPNM.read((char *)buf,max);
        if( (i = readPNM.gcount()) != max)
        {
            cout << "Error reading bin file\n";
            cout << "Expecting " << max << " bytes but found only " << i << " bytes.\n";
        }
        for(i = 0; i < max; ++i)
            img_pix[i].rgbb[0] = buf[i];
        delete[] buf;

My guess is the reason the file is not big enough is because the remaining unwritten bytes are some default value, such as -1 (or 0x255), 0 or some other default value. From this information I would presume not only do you have to save width and height, but also the number of bytes that are actually in the file so that you can write back out exactly what was read, which might be a value less than width*height.

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

Is this c++ ??? Never heard of XPath.

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

i think a month ago i found that forum, then i saw that total number of threads in the forum was 20, so i was a little frustrated. our company extended the functionality on the raima database and there is no documentation for those additional methods..

It's not Raima's fault there is no documentation for those extensions. But I see what you mean about the lack of threads -- they must have cleaned out all the old ones or started a new forum recently because I know it was fairly popular when I was using it 20 years ago.

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

bring your forum to here, we as daniweb citizens wouldnt bother to go there :)

Why? Don't limit your programming experience just to DaniWeb. If you have questions about specific database then get it from the horse's mouth.

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

I used Raima databases 20 years ago when I was writing MS-DOS 6.X programs. At that time Raima was a hierarchical database (non-SQL) and quite easy to use. Several years ago Raima expanded its product to an SQL database, but I have not used it. AFAIK its language is pretty SQL standard, so if you read about one SQL database you can apply it to most any others.

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

Are you implying that I've mellowed out, AD?

Yes -- people tend to do that as we get older :)

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

if she hadnt have a boy friend... ;)

Probably her husband -- she has children so I assume she is probably married. But one can't really say nowdays :)

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

>int size=0;
>int *parr= new int;
For starters, size isn't a compile-time constant, which means you're relying on a compiler extension and your code is thus non-portable

I think you just had a brain fart :) There is nothing wrong with calling new with a non-const integer. Maybe you were thinking this: int parr[size];

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

Amazing. Visiting the Geeks' Lounge is like sitting in a room full of children.

Maybe because half DaniWeb members ARE children. How many members posting here are under 21 years old?

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

At this point I think you probably need to use your compiler's debugger, put a break point on that write line and inspect the value of that array. You have only posted one line from your program so its pretty impossible for anyone to tell you the solution to the problem. Possibly its not that line at all but somewhere else in the program, such as memory corruption.

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

From what you posted earlier it still looks like rgbb is uninitialized. Do you write rgbb in text files too?

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

Probably a permissions problem. When doing backups, what account is the backup program running under? It needs to run under an account that has admin permissions on your XP computer.

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

Its a pointer to struct PIXELS with :
int rgb[3];//for ascii
char rgbb[3];//for binary

why not just use a union, which means the same memory location could be accessed by either an int or char array

struct PICX
{
    union {
       int rgb[3];//for ascii
       char rgbb[sizeof(int)];//for binary
    }
};

>>PIXELS *img_pix = new PIXELS[width*height];

writer.write(reinterpret_cast<char*>(&img_pix.rgbb[0]) ,sizeof(&img_pix.rgbb[0] );

Does rgbb contain anything? Is it just an uninitialized array? Use the union concept mentioned above might resolve that if your program populates the int first.

[edit]
On second thought, if all you use rgbb for is to write out to the file, then you don't need it at all nor would you even need the union

writer.write(reinterpret_cast<char*>(&img_pix[i].rgb) ,sizeof(img_pix[i].rgb));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi again
I opened the new file with word pad, the problem is theres a lot of memory junk being writed on the end of the file (ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ...) lots and lots

Any idea of what can I be doing wrong?

You aren't doing anything wrong. You can't view binary files with Notepad because they contain binary data that Notepad doesn't know how to display. Notepad can only display text files, not binary files.

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

who is the guy playing the guitar?

I have no idea who he is. I was just listening to that video because of its content when it turned into someone playing the guitar, and I thought you might be interested.

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

Theme from piano concerto no.1 , peter Tchaikovsky, for guitar
http://www.youtube.com/watch?v=mCLAAAoqhcQ

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

use static allocation unless (1) your os and compiler have very limited stack space, or (2) the objects are huge. Declaring STL containers like vector dynamicall is just a waste of time/effort because they only consume about 20 bytes of memory anyway.

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

Note that fgets() will also append '\n' to the end of the string if it appears in the input stream.

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

don't clear it before freeing, clear it immediately after using it. The purpose is so that unused elements can be easily detected. For example line 309: before the return statement you have to free up all the memory that was allocated up to that point. If you don't then it will cause memory leak.

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

Learn to use your compiler's debugger and step through the code one line at a time so that you can see what it is doing.

line 292: you are attempting to treat a 2d array of REALIZATION structures as if it were a 1d array. It needs two stars, not one =REALIZATION** generation = 0; . The rest of the code in that function should then work ok.

After allocating the array you need to set all elements to NULL so that they can be correctly free()ed, expecially if the function returns prematurely (see below). memset(generation, 0, generationSize * sizeof(ACTUAL_CHORD *)); lines 309, 330 and 338: memory leak here. You need to free() variable generation and each of the pointers that were returned from spawnRealization().

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

write a wrapper function such as mywrite() and call it instead of fwrite().

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

Thanks Narue. Here is my first post. It doesn't appear that I ever posted in Community Introductions. :icon_redface:

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

When I joined there were a bunch of know-it-all wannabes running around giving bad advice in the C and C++ forums. I'm fairly confident that my first post was a correction to one of their posts.

The earliest post I can successfully find is on September 26, 2004 (clicky), which is pretty close to my join date, but still short ten days worth of posts.

I can only find the most recent 500 posts I've made. I click on my profile then select the Find All Posts link, and only 500 posts are reported. Is there a way to get them all?

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

foo2( ) will also give the size of the pointer, not the array.

You are absolutely right!

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

I have over 12,000 posts and can't possibly tell you the first post I made. A search of all my posts doesn't work either because they are no longer on the server, but probably archived off somewhere.

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

[color][b]

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

I don't think that's what he meant. Character arrays passed as a parameter to other functions can be passed as either a pointer or a character array. So the same rule applies to the sizeof() operator there as well

void foo1(char *mystring)
{
   // here mystring is just a pointer, so the sizeof() operator
   // will produce unexpected results
}

void foo2(char mystring[25])
{
   // here mystring is a charcter array and the sizeof() operator 
   // will work as expected
}

int main()
{
    char mystring[25];
    foo1(mystring);
    foo2(mystring);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can read about my reasons here. Browse around the other archive articles and you will find many other members and their reasons.

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

sizeof( colour ) probably isn't going to work. The sizeof( ) operator only gives the size of the array in the function where the array was declared. All you are likely to get here is the size of a pointer.

.

I was assuming colour was a character array, not a pointer. But if it is a pointer then of course you are right and the op needs to pass an integer constant that indicates the max size.

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

did you try #include <mysql/mysql.h>

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

Did you install mysql database on your computer? If no then I think you may have to install mysql on your computer in order to get the header files etc.

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

for linux just change c:\blabla to whatever it is on your computer.

>>When I did locate mysql.h , its not in my system
you mean its on another mounted file system? That should be ok, You will also have to do similar for the mysql libraries so that your compiler can link to them.

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

you need to add the include path to mysql.h
INCLUDES="c:\mysql\include"
$(CC)-o mysqlrun $(INCLUDES) $(MYSQLCFLAGS) mysql.c $(MYSQLLIBS)

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

The structure is wrong -- need to add another character to each element for the null-terminator

struct bday{
	char month[3];
	char date[3];
	char year[5];
};

or just make them ints

struct bday{
	int month;
	int date;
	int year;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are two versions of getline() -- one for character arrays and the other for std::string. If variable colour is a character array then use cin.getline(colour, sizeof(colour)); , otherwise if colour is a std::string then getline(cin, colour);

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

>>is it bad practice to put an assignment in an if statement?
IMO -- no, I have done that occasionally, especially in loops

int x;
while( (x = getnumber() ) == 0)
{
   // do something
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>for(i=0;i<=2;i++)
That will print 3 structures, not 2. what you want to do is use the < operator, not the <= operator.

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

line 28: delete that if statement because if the program gets that far its 100% true that the word was not found. So all you need to do at that point is display the error message.

lines 22 and 23: you have already read the line that begins "Hardtop" on line 18. Lines 22 and 23 just read the next line. What you need to do is use stringstream to split the line that was read on line 18

stringstring str(line);
str >>  body->style >> body->doorCount;

Another way to do it is to change the loop on line 18. The problem with this approach is that it will destroy the values in that structure/class. So if that's not what you want then don't use it.

while( file >>  body->style >> body->doorCount)
{
    if( body->style == key)
          return true;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>char *array;
That is not a 2-dimensional array. char **array is how to declare it, using two stars not just one.

Here is one way to initialize it

char **array = 0;
array = new char*[rows];
for(int i = 0; i < rows; i++)
    array[i] = new char[columns];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if (seats[position]=0)
You need to use the boolean operator == instead of the assignment operator =.

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

if you can't use standard C function strcat() then your function looks ok to me. But you could also use pointers

void concatString(char *szTarget, const char* szSource)
{
     while( *szTarget ) 
           szTarget++;
     while( *szSource )
          szTarget++ = *szSource++;
     *szTarget = 0;
}