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

Welcome to DaniWeb. It's not how old you are when you start but how well you can think and solve problems. I was almost twice your age when I started.

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

First you have to have mysql server installed on your computer. Then you have to link that program with the mysql.lib that is in the mysql server install directory.

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

Any predictions of world disasters?? Earthquakes, hurricanes, tornadoes, huge sun spots, earth hit by large asteroids, etc.

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

>>but how can I keep reading it, line by line?

That's the purpose of the while statement that you posted. Every time fgets() is called it will read the next line in the file. The "!= NULL" says to keep reading until end-of-file is reaches or some other error occurs.

Yes, strtok() is one way (and probably the easiest) to extract the words.

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

Have you created the database and tables yet? What's the name of the table, and whats the names of the columns?

You need to learn the SQL (Structured Query Language). google for tutorials.

Briefly, if you want to insert a row into a table

INSERT INTO tablename VALUES(1,2,3,4,5)

Where 1,2,3,4, and 5 are just the values you want to insert for each of the columns in the table. 1 will be put into the first column, 2 into the second, etc.

If you want to insert text strings instead of numeric data then the strings have to be surrounded with ' character

char cmd[255];
sprintf(cmd,"INSERT INTO tablename VALUES('%s','%s','%s','%s');", tokens[0],tokens[1],tokens[2],tokens[3]);

With that, you have to call the mysql c api function to process the statement. I'm not going to tell you how that is done -- read the tutorials that are on the mysql web site.

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

by "protected/unprotected code" to you mean "managed/unmanaged code" ? Maybe you should contact NUnit to iron out the problems you have with it. I never used it so I can't help you with it.

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

Sounds like you have some studying to do in order to make up that week in the hospital. Your text book probably covers all the material you need to do the program.

Start out very simply -- define the class.

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

using wild cards may result in sql errors if two or more tables have duplicate column names. The result set must have unique column names.

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

Here is one solution, the same as used by many win32 api functions because it avoids the problems of allocating memory in DLLs.

void __stdcall date(char* dateStr, size_t size)
// dateStr is allocated by calling function
// size is the number of bytes allocted to dateStr
	
{
		 
    _strdate_s( dateStr, size); // fills char array with date
}

Or if you want the function to return something

char* __stdcall date(char* dateStr, size_t size)
// dateStr is allocated by calling function
// size is the number of bytes allocted to dateStr
	
{
		 
    _strdate_s( dateStr, size); // fills char array with date
    return dateStr;
}

Example calling function

int main()
{
   char dateStr[50];
   date(dateStr, sizeof(dateStr));
   cout << dateStr << '\n';
}
Suzie999 commented: Very helpful, exactly what this noob needed. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I would not use that code because it has other issues as well. Write your own program to avoid having to debug other people's code.

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

Like I said, read a line, do whatever you want to it, then rewrite the new line to another file.

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

The algorithm is almost identical to single column sorting. The only difference is in the swapping of values -- when a swap is needed then swap all columns in the rows.

An easier, and quicker, way to do it is to do indirect swapping, where you have a second single column int array that contains index numbers (0, 1, 2, 3, ...). When a swap is needed just swap the index array

Example

#include<stdio.h>

void show(int ay[5][5], int index[5])
{
    // display the array
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            printf("%-4d",ay[index[i]][j]);
        }
        printf("\n");
    }
    printf("\n");

}

int main()
{
#define sortcol  3

    int ay[5][5] = {{ 4,3,1,5,2 },{10,4,9,15,3},{8,4,7,2,1},{15,42,35,21,4},{9,20,14,17,2}};
    int index[5] = {0,1,2,3,4};
    int i,j;
    show(ay,index);
    for(i = 0; i < 4; i++)
    {
        for(j = i+1; j < 5; j++)
        {
            int a = ay[index[i]][sortcol];
            int b = ay[index[j]][sortcol];
            if( a > b )
            {
                int temp = index[i];
                index[i] = index[j];
                index[j] = temp;
            }
        }
    }
    show(ay,index);

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

@abh7i: You will want to do lots and lots of reasearch before you start to do anything. You can't hope to start any kind of company before you have the answers to the questions you posed.

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

You realize that 1000x100000 array occupies 400,000,000 bytes ( or 400 megabytes) That's a pretty huge array and will probably slow down your program to a crawl.

Lean to use std::vector, its not all that difficult. std::vector will only use the amount of space actually needed. Learn to think outside the box occasionally.

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

>>I have fought with this for 10 hours and once again I'm so losing
the battle vs C++ char arrays and strings.

Because you must be too pigheaded and stubborn to listen to the advice I gave you in my previous post. You just wasted 10 hours for what? Nothing. Had you bothered to read my post 15 hours ago you would have discovered that what you are attempting to do can not be done.

I already told you that character arrays can not be returned from functions. Why? because the array is destroyed as soon as the function returns.

>>ss << dateStr[0];
That doesn't work becase all it does is put the first chararacter of dateStr into ss. If you want to put the entire string then do this: ss << dateStr; . But why are you using stringstream here? The code you posted does nothing with it so you might as well just delete it.

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

Person is the same thing that you originally posted. Its just another name for struct tagPerson Person is not an instance of the structure, but just a typedef for it.

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

why do you need a 1000X10000 array?

Another way to do that and simlify it is to create a structure then make an array of structures

struct item
{
   vector<int> numbers;
   int linenum;
};

vector<item> items;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Which every 5th word needs to be replaced with an underline

You mean that isn't right? Then what is it? The only way to do that is to count words. I suppose you could read the file one character at a time then check for isspace() to find the end of words. Something like this -- which was not compiled nor tested, so it might contain errors.

int counter = 0;
char c;
ifstream infile("filename.txt");
while( infile.get(c) )
{
   if( isapce(c) )
   {
      ++counter;
      // now ignore all consecutive spaces
      int ch = infile.peek();
      while( ch != EOF && isspace(ch) )
      {
         infile.get();
         ch = infile.peek();
      } 
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Try it out for yourself and see if it works for you.

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

you are not making any sense. Where to put what??

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

I cut my teeth an older version this one by Peter Norton, way back in the days before MS-Windows

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

Seems to be fixed for now.

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

I play a game of chess between loads :)

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

You are doing it the most diffiult way possible -- reading the file one character at a time. Words are separated in files with white space (spaces and/or tabs). ifstream has >> operator which reads entire words

std::string word;
ifstream input(filename.c_str());
int counter = 0;
// check that file was opened
if( input.is_open())
{
    while( input >> word ) // read an entire word at one time
    {
       ++counter;
       if( counter % 5 == 0)
       {
          // output underline
       }
       else
       {
          // output original word
       }
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I agree. I don't recall ever seeing a drunk Ninga or a boozed-out rugby team play :)

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

predeclare the structure

typedef struct tagPerson Person;
struct tagPerson
{
  // blabla
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you have given where should that be put?

Do you really want me to tell you where to put it?? :)

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

character arrays like that can not be returned by any function, whether its in a dll or not makes no difference. You have several options

  1. Since this is c++ return std::string -- this may have the same problem as described below for #3
  2. add a char array parameter to that function void __stdcall date(LPSTR dateStr, size_t size)
  3. declare dateStr as a pointer and allocate memory for it. This is least desireable because the calling function has no way to delete the memory. Memory allocated in a dll must be deleted (or free'ed) in the same dll.

>>LPSTR string = "";

That declares a pointer which points to a character array of only 1 byte -- the NULL terminator.

>>string += dateStr;
This will not work with character arrays. All that it is doing is incrementing the pointer by dateStr number of bytes. If dateStr == 'A' then pointer is incremented by 65 bytes because 'A' has a decimal value of 65. Its the same as this: string += 65; That is clearly not what you intended.

Lines 7-11 do not seem to have a purpose anyway, so just delete them.

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

I don't follow golf -- afterall its no more a sport than computer programming or brain surgery. Anyone can play golf, whether sober or intoxicated; as long as your not passed out you can play the game.

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

int 21h is a general purpose interrupt with many different functions -- each function is identified by the value of the ax register. google for in21 functions and you will find them all.

If you want to learn assembly then the place to look is in a good book.

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

Nope. Just look through that link and see if anything jumps out at you. I don't even know if it contains anything useful.

This is how to get a list of all running processes and their thread IDs (MS-Windows doesn't use PIDs). I don't have time to research this right now, but there might be a windows function to enumerate the open file handles given the process ID.

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

I supose you should post an example HTML file. If you can already extract all the data from the table then what's the problem? Is the data numeric or strings, or both?

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

sprintf() will do all the conversions except binary. Google for binary to decimal convertions and you will find out how to do that too. If you are not allowed to use sprintf(), such as you must write the algorithms yourself, then use google because such algorithms are very common and have been posted for quite a few years now.

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

I suppose the easiest way would be to use boost HTML parser

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

I'm having a wonderful time living since I retired from programming a little over 3 years ago. Life is sooo much easier and better. I wake up every day without a care in the world. Even though I still work part time (non programming) I never bring my work home with me or have nightmares about it :) :)

So how's my day? As Tony The Tiger would say "Grrrrrrreat!"

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

1) Yes that is correct

2) Its not really hidden if you look around Eclipse options -- I don't use Eclipse so I do know. Eclipse probably generates a makefile that g++ uses.

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

If you want MS-Windows then probably have to use one or more of the Undocumented Windows API functions

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

or like this, where there is only one return statement

bool function(int a)
{
   bool rvalue = false;
   if(a == 2)
   {
      // do something
      rvalue = true;
   }
   else
   {
      // do something else
      rvalue = false;
   }
   return rvalue;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When main.cpp is compiled the compiler generated main.obj (or main.o depending on the os). When custom.cpp is compiled the compiler generated custom.obj. The linker uses both main.obj and custom.obj, as well as other libraries, to create the executable program.

How does the linker know how to do that? It depends on the compiler and IDE you are using. With both Code::Blocks and VC++ 2010 you have to start out by creating a project then add both main.cpp and custom.cpp to that project. With olther command-line driven compilers you might have to create makefiles, which is a text file that tells the compiler and linker what to do.

No point in being any more specific until you tell us what compiler and operating system you are using.

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

From the description I would think you need to read the numbers from a text file, not from the keyboard.

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

int 21h, ax = 09, writes the string in dx to the screen. You would have known that if you had bothered to google for "int 21h".

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

>>plz don't ask question from me try to give me some suggestions

Ok -- you're ignored.

Orion2k commented: gay +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Think of a class as an entity all on its own -- the class has no knowledge of anything outside its class. It's not possible for a class to access objects declared elsewhere in the program.

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

It is a lot more difficult in C language see ODBC tutorials

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

Which version of Visual Studio 2010 are you using?

>>well first of all I ask u people don't try to give me advices like use QT instead that waste my time lot
With a statement like that you are likely to not get any advice at all.

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

>>It now works
No it doesn't.

>>for (n = 0; n <= num; ++n)
Change <= to just <

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

You mean you want to sort the array without actually swapping array values? I have done that before but used a second array of intgers that represent the array indices.

float data[5] = {3,1,4,9,2};
int indices[5] = {0,1,2,3,4};

// sort the data
for(int i = 0; i < 4; i++)
{
  for(int j = i+1; j < 5; j++)
  {
     if( data[indices[i]] < data[indices[j]] )
     {
        int temp = indices[i];
        indices[i] = indices[j];
        indices[j] = temp;
     }
  }
}

// now display the values
for(int i = 0; i < 5; i++)
   printf("%f\n", data[indices[i]]);

This technique is a good way to sort large 2d arrays also because it greatly reduces the number of items to be swapped during sorting. The contents of the original array are unchanged.

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

two things
1) what is the value of n before that loop starts? Uninitialized variable is the most likely reason the data is not being written to the file. Add n = 0; on line 6 and see if that doesn't fix the problem.

2: The code is not writing the first row in those arrays because the index counter is being incremented before the write. Arrays are numbered 0 to whatever, not 1 to whatever. Move line 9 down after line 11.

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

Do you mean how to sort a 2d array based on just one of its columns? For example if you have an array of ints that has 5 columns and 1,000 rows, how to sort it by the contents of column 2 (or some other number) ?

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

should have been plrs.id = j;

>>As a quick fix I've changed it to plrs.id=i+1;
Well you changed it wrong. Your original code snippet in your first post was correct for that line.