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

You need to look for WM_KEYUP and WM_KEYDOWN events. Here is an example thread.

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

No functions -- to erase just redraw with same colors as the background.

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

1. Just read the fields one at a time into an instance of the Song class, then add the Song class to the vector

vector<Song> theList;
Song s;
infile >> s.title >> s.artist >> (etc etc for each field)
theList.push_back(s);

2. You can use an iterator for this

int recordno = 1;
vector<Song>::iterator it = theList.begin();
for( ; it != theList.end(); it++)
{
  cout << "record number: " << recordno++ << (*it).title << "\t" << (*it)artist << "\t" << (etc. etc)
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I get what your saying now, but everytime i try to use a for loop to insert the characters one at at time the program crashes.

I am not sure what i am doing wrong?

All you have to do is this:

int main()
{
   std::string saveString;
   ..,.
   ...
// line 77
   saveString += characterDecodedChar;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> sizeof( any pointer ) is always the same

>> That happens to be true for the garden variety PC of today, but it is not true as a generic statement.

Also, on the same system fat pointers are bigger than normal pointers... http://en.wikipedia.org/wiki/Function_pointer#Method_pointers

Never heard of a "fat" pointer before now.

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

1) line 15: you need to check of strtok() returns NULL.

2) line 19: memory leak. You allocated a character on line 17 then toss it away at line 19.

3) line 22: temp has only been allocated to hold one character, yet you are attempting to copy an entire string into it. This is probably what is causing your program to seg fault.

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

Where is the code you have tried ???

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

Must be something else. What compiler/os are you using?

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

Well Narue the posters in your examples deserve a lot more than simple down votes! The deserve to be flamed, royally. But I don't think (I hope) those are the kind of threads they are talking about here.

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

why the pointers?

int function(user* users, int id, char name[], char surname[]){
strcpy(users[id].name,name);
strcpy(users[id].last,surname);
users[id].id=id2;
}

And in main() you need to initialize the strings and int before passing them on to that function. If you don't then your program will just be so much crap.


It will also make is much more clearer that users is an array of user structures instead of a pointer to one structure if you code this: int function(user users[] ...

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

why can't you do that yourself? (I don't know java so I can't help you)

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

1) what compiler are you using

2) what error messages do you get.

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

line 25 is not necessary. You don't have to specifically load win32 api DLLs.


>>If I have to use shell execute not in MFC
I didn't ask you to use MFC -- MFC has nothing to do with ShellExecute function. Had you bothered to read the link I gave you, you would have seen that the first parameter can be NULL.

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

you can't draw directly onto the desktop. You first have to create a windows gui program and draw on its canvas.

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

Its really a very simple concept (link here)

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

call win32 api function ShellExecute


More here

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

line 77: why don't you just same the characters in a std::string object so that you can easily write it to a file??

function counter() -- its too lengthy and too complicated. The following will work if ch is always an alphabetical letter 'A'-'Z' or 'a'-'z'.

void counter(char ch) {
    char c = tolower(ch);
    lettercounter[c-'a']++;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Take it one small step at a time, and soon you will have that program written. First learn how to open a file and read it one line at a time. After you have that working, learn how to split up the rows into columns (you can use stringstream c++ class for that). Then make the menu, add a switch statement to implement each menu item.

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

Post your text file -- that worked ok for me using vc++ 2008 express.

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

sizeof( any pointer ) is always the same -- sizeof returns the number of bytes it takes to store the address of the pointer, not the length of the string the pointer references. So lines 12 and 13 of your code will always return the same value (probably 4).

line 14: you are attempting to store an unitialized pointer into the vector. undef points to just some random memory location, and that may cause a seg fault, especially if you later attempt to do anything with that pointer.

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

>>How do i assign a string to a array?
1) add #include <vector> 2) create an array of strings vector<string> aList; 3) add a string to the vector: aList.push_back( "Hello World" );

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

I assume you mean SQL type databases, such as Microsoft Access, SQL Server, Sybase, Oracle, etc. win32 api does not support databases. You have to use something else, like ODBC.

If all you want is simple files then use the functions in <fstream>. Google is your friend, so google for fstream and learn all about it.

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

To create a new console application: From the menu File --> New --> Project, select Win32 in the Project Types, then Win32 Console Application in the Templates. At the bottom enter the project name and location, then hit Ok button. The rest you should be able to figure out. If not, then just ask

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

put the lines in another function then call that function from whereever you want.

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

you are attempting to put code outside a function. Lines 7 and 8 have to be inside a function.

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

Here is another way to do it (standard c++). Create a structure that holds the data for one line, then a vector of those structures.

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

struct data
{
    string name;
    string address;
    string postCode;
    string phone;
    string details;
    string var1;
    string var2;

};

vector<data> dataList;

void parseLine(data& d, string& line)
{
    string n;
    size_t pos = 0;
    int count = 0;
    while( line.size() > 0)
    {
        if( line[0] == '\"' )
        {
            pos = line.find('\"', 1);
            n = line.substr(1,pos);
            while(pos < line.length() && line[pos] != ',' )
                pos++;
            if( pos == line.length())
                line = "";
            else
                line = line.substr(pos+1);
            switch(count)
            {
            case 0: d.name = n; break;
            case 1: d.address = n; break;
            case 2: d.postCode = n; break;
            case 3: d.phone = n; break;
            case 4: d.details = n; break;
            case 5: d.var1 = n; break;
            case 6: d.var2 = n; break;
            }
            ++count;
        }
    }
}

int main(int argc, char* argv[])
{
    data d;
    string line;
    ifstream in("myfile.csv");
    while( getline(in, line) )
    {
        parseLine(d, line);
        dataList.push_back(d);
    }
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First you have to learn how to generate the list of prime numbers. There are lots of examples here, just search for them. Use the "Site Search" button located in the upper-right corner of the DaniWeb yelllow (gold?) band.

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

you can't do it like that either (which you have already found out). use sprintf() to format the string, like this: Note in the below code variable buf can NOT be a pointer.

char buf[255];
sprintf(buf,"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d", (int)index);

My computer is 64-bit quad-core and the value of ProcessorNameString is the same for each key. So if that's all you want then all you have to do is get the name from the first one, and you might just as well hard-code it "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"

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

Your timer event handler is probably doing something that makes the screen to be repainted. If the event handler takes a long time to process then turn kill the timer at the beginnning of the event handler and restart it just before it returns to prevent MFC from calling it again before it is finished.

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

>> "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\"+(char)index
You can not concantinate a double to a float like that.

What you want to do is enumerate all the keys with the CentralProcessor key.

Here is what you want:

int main ()
{
	HKEY key;
	LONG succeeded;
    std::string keyname = "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\";
    std::string processor_name;
    vector<string> processor_list;

	succeeded = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname.c_str(), NULL, KEY_READ, &key);
	if (succeeded == ERROR_SUCCESS)
	{
		char *value = "";
		DWORD value_size = 0;
        bool done = false;
        for(int i = 0; done == false; i++)
        {
            char buf[255];
            succeeded =  RegEnumKey(key, i, buf, sizeof(buf));
            if( succeeded != ERROR_SUCCESS)
            {
                done = true;
                break;
            }
            cout << "key: " << buf << "\n";
            HKEY key1;
            string name = keyname + buf;
            succeeded = RegOpenKey(HKEY_LOCAL_MACHINE, name.c_str(), &key1);
            if( succeeded == ERROR_SUCCESS)
            {
                value_size = sizeof(buf);
                memset(buf,0,sizeof(buf));
                succeeded = RegQueryValueEx(key1, "ProcessorNameString", 0,0, (unsigned char*) buf, &value_size);
                if( succeeded == ERROR_SUCCESS)
                {
                    cout << buf << "\n";
                }
                RegCloseKey(key1);
            }
        }
    }

	RegCloseKey(key);
        
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 9: >> char *value = ;
Will that even compile ????

>>DWORD value_size = sizeof(value);

value is a pointer, and the sizeof(any pointer here) is 4 on most 32-bit platforms.

you don't have to put that in a loop. Call it the first time with the size of the buffer = 0 and it will return the required size

If the buffer specified by lpData parameter is not large enough to hold the data, the function returns ERROR_MORE_DATA and stores the required buffer size in the variable pointed to by lpcbData.

if( (RegQueryValueEx(key, "ProcessorNameString", NULL, NULL, (BYTE *)value, &value_size) == ERROR_MORE_DATA )
{
     value = new char[value_size];     
    (RegQueryValueEx(key, "ProcessorNameString", NULL, NULL, (BYTE *)value, &value_size);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 31-36: You are getting a character from the keyboard but tossing it into the bit bucket (not doing anything with it). You need to create a character array and save the characters in it.

>>strtok(c," "),

strtok() works on character arrays, not single characters. Passing variable c as the first parameter will not work because it is not a character array.

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

line 18: >> fstream* file = new fstream( "myfile.txt", fstream::in);

There is absolutely no reason to complicate things more by making fstream object a pointer which has to be allocated. Just create an fstream object fstream file("myfile.txt, ios::in); . Note that ios::in will NOT create a file if it does not already exist. If the file doesn't exist the only way to create it is to open it with ios::out flag or use ofstream instead of fstream.

kvprajapati commented: Good suggestion. +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well, if we want to talk about our ages -- I'm 66 and retired American Air Force (1985). Fortunately I survived View Nam with no injuries. But I would not presume so much as to use my age as am excuse for being an old grouch. Nor are old war injuries an excuse for being nasty here at DaniWeb.

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

The version of windows.h that is supplied with VC++ 6.0 is a little buggy. Dowload and install the Windows Platform SDK which has those bugs fixed.

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

why is year a double??? There are no decimal places in a year unless you want 1.5 to be a years and 6 months.

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

>>What datatype should I use for storing the line? ie: the 'storelinevariable' parameter?

If you use getline() then it has to be std::string object

What do you want to do with the lines after they are read into memory? Do you need to use individual columns, do you want to put the data into some sort of structure of c++ class then make a vector of them? Or just simply store the entire line into a vector?

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

Compatibility mode has existed since windows XP came out, its not a new feature.

Are you sure about that? I never heard of it until Windows 7. And its not available on the Home edition. I've also read that xp compatibility mode is a lot of crap -- very very slow.

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

I accept that some, or most, of my answrs have been done in haste but as an older generation person, my mind is not as sharp as some of you younger people. Also, being disabled, I'm unable to sometimes clarify the point I'm trying to make.

Oh so now your trying to blame it on your age and disabilities :D I don't see how either is relevent to your problems here.

lllllIllIlllI commented: Oh yeah, here at daniweb, its not often old people do a proper answer :P +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>and your last suggestion (test<'1') only could be used if we declared the variable as char

Oops -- it should have been text < "1"

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

See the MS samples from SDK and on Professional Win32 group http://tinyurl.com/yjy3ajr
(from Windows source code itself...)

That was not the same question, although good to know too :)

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

>>See rather the Microsoft sample
What sample? Post link.

[edit] Probably this?

>>posted 10000 times on BBS & Usenet.
Probably -- now its been posted 10001 times :)

tux4life commented: Well said. +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is you cant compare a string to an intenge.

The program is not comparing a string to an integer, "1" is a string, not an integer.

>>EDIT: If you really want to compare to a number you could compare like this:
test != "1" && test != "2", else you cannot do unless you declare test variable as an intenger

That's not correct either. test < '1' works just great. Compile and run the program and you will find out.

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

The while statement is wrong. If I enter a '1' the loop will continuje because it is not an 'a', which is one of the tests. Try this while (test<"1" || test>"5" && test !="a" && test!="b");

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

Is there a question somewhere?

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

what's your program going to do if I enter 15 for rows and 20 for columns???

Do you have a question about the code you posted?