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

The else is in the wrong place. Move it after that for loop. When the for loop ends, check to see if variable done is still false. If it is, then display the error message.

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

recursion will work, providing the message isn't too long.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
bool done = false;
while( !done )
{
  
    getline (cin, Command);
    Name[K].Firstname = Command;

    for ( T = 0; T<30 ; T++) 
   {
       if( Name[T] == Name[K].Firstname)   //K is a static variable because this is a program that will run forever and will save each and every name within the Name[K]Firstname that the user enters.
        {
           cout << "Correct";
           done = true;          
           break;
        }     
        else
        {
           cout << "Invalid Species try again :"  << endl;           
        }
      }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will have to implement some sort of thread synchronization scheme in order for the threads to access a single commen queue to prevent corruption of the queue data. That means only one thread can access the shared common queue at a time -- all other threads that want to access it will have to wait their turn. If you are not very careful that could cause a deadlock situation.

Creating and using a mutex is one way to do it, assuming your os supports them. Since it supports multithreading then I would imagine it would also support mutexes.

My question is how can I communicate from the main thread to a worker to get data from the buffer in a lock less or in the least amount of locks using either pthreads or glibmm::threads

About all that the main thread can do is set a global variable that indicates new data is available in the queue. Then the threads check the status of that variable and act accordingly. Another possibility is to use signals -- main sets a signal and the threads catch it???? I don't know if that will work or not.

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

Well, what does "%n" do in scanf()? I couldn't find any reference to it here. And it seems to not do anything in the code that's been posted in this thread either. But if I enter
HelloWorld 1 2
Then the string length is correct, for some odd reason.

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

>>It seems to me that it's working correctly, with your input:
What I meant was that it doesn't answer the OPs question of how to get the string length without calling strlen() (or similar function).

>>Doesn't there have to be a check which prevents an array boundary overrun?
Yes, there should be, but its not required. You can let scanf() scribble all over memory if you want to.

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

Pay attention! This is not the C++ forum

True, but you failed to answer the question, most likely because you don't know the answer any more than I do.

Aia commented: Let me show you how to give negative reputation: Pay attention! Don't be lame! -2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sounds like homework. Read your textbook or google.

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

i dont have much experience in registry . will u provide me working code

The best way to learn it is to do it yourself. I already gave you the link to the function you need to call. Experimenting with functions that you do not know how to use can be very enlightening. Instead of me just handing over the code to you, you give it a try and post back if you still have problems. Also post the code you tried.

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

That doesn't work

1 2 HelloWorld 3
len = 1
Press any key to continue . . .

int main(){	
	char R[255] = {0};
int s, e, n;
scanf(" %n%s%n %d", &s, R, &e, &n);
int len = e - s;
cout << "len = " << len << '\n';
return 0;
	}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you logged into Windows with Admin account?

In vc++ perform Build --> Clean Solution then Build-->Rebuild Solution. In VC++ 2010 you might have to activate that Build menu by selecting Tools -->Settings --> Expert Settings.

Post the program, or testable code snippet that demonstrates your problem, so that we can test it.

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

My mistake -- "microsoft security" is a value, not a key. So you first have to open the key as you did in the first program

RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run",&hKey)

Then attempt to read the value of "microsoft security" by calling RegGetValue()

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

You can't do it like that because you have to give it the full path to the key you want to open

RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run\\microsoft security",&hKey);

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

And you point is???

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

why are you mixing malloc() and new in c++ program? Replace malloc() with new only.

>>i only set it to 0 in my code yet it changes it self somehow
See line 91 of mastermind.cpp

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

What, then constitutes .NET?

Read this wiki article

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

You could pad your format string with %n conversions, which would give you a length with a minimal calculation.

how would that help?

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

>>is it possible to get the length of R as a by product from scanf
No.

jonsca commented: Best answer I've seen all day +4
jephthah commented: actually, it's not a very good answer -1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

cout << "Value name: " << name << "---" << "Data name: " << *(DWORD *)name2 << endl; As I said you will have to type cast the BYTE* into DWORD*

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

>>how to make this event run every timer tick?

OMG you don't want to do that! If you did it would consume all the CPU time that your computer has, leaving nothing for any other programs.

Most likely what you meant was on every second. Timer ticks and seconds are very different things. There are (usually) 1,000 ticks per second.

As for your question, I don't know the answer because I don't do managed c++.

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

Spend a year or two learning C and/or C++ and you will be able to write that program yourself. Otherwise, deposite $10,000USD in my PayPal account and I'll write it for you -- someday.

The program specs you posted do not say what you want the C program to do -- only what MS-Access file to use. What exactly is it the program is supposed to do with that file ?

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

>>Hi, I'm working on a c++ homework assignment and I cannot get it to work.

What part of your program doesn't work? Explain in detail.

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

He won't get an error, it just don't do anything. Why use offset of 0 except go move the file pointer to either the beginning or end of the file????

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

1. get current time in the form of struct tm (two function calls to do that)

2. Get number of days from user

3. Add days from #2 above to tm_mday obtains in #1 above

4. call mktime() to normalize all struct tm members.

Note: you can't do silly things like advance number of days beyone the limits of time_t or subtract them to that the result is before 1 Jan 1970. If you want to do that then you will have to use something else, such as write your own function to handle such times.

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

What compiler are you using? Your program compiled and linked ok for me using VC++ 2010 Express and Code::Blocks w/Mingw.

The last two parameters of lines 12 and 13 are wrong. Should be this:

RegSetValueEx(hKey, "Shell", 0, REG_DWORD,
	NULL, 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I thick you can use fseek.
fseek() is intended for binary fines, not text files. Its pretty much useless for text files.

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

>>how can i update a text file i,e only one particular record in a file

The only way to do that is to completly rewrite the text file, making whatever changes you want while doing that.

Salem commented: Yes +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Did you use regedit program to view the contents of those data items? Are they strings or something else, such as integers? My guess is that your program needs to check the data type and make appropriate cast before attempting to display them.

Also check if strings are null terminated. From MSDN

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, the string may not have been stored with the proper null-terminating characters. Therefore, even if the function returns ERROR_SUCCESS, the application should ensure that the string is properly terminated before using it; otherwise, it may overwrite a buffer. (Note that REG_MULTI_SZ strings should have two null-terminating characters.)

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

SqLight is free, but I don't know the max file size it supports. Since you have to compile it with the application program my guess is that it supports files as large as those supported by your compiler.

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

Post the error message the compiler gives you.

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

If you don't want her, give her my personal email address.

I'll gladly forward them all to your PM box too :)

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

Post your teacher's email address and the course number of the class you are taking so that we can e-mail the program to him/her.

Fbody commented: LOL :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first place to start is to improve the program's formatting. Writing the code with everyting starting on the left margin is not only ugly but very difficult to read. You might get more responses by improving the program's formatting.

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

AD, that made me lol. Later--

Its a very old, but often effective joke.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while(true)
{
    read post #16;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Be careful what you ask for :)

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

The only problem I found was line 16: you have just one colon instead of two after std. Otherwise it worked ok for me with Code::Blocks on Ubuntu.

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

>> cout<<"Repeat?(y/n)";
>> cin>>ans;

You need to clear out all the extra stuff in the keyboard buffer, such as the <Enter> key '\n' before continuing after that cin. Try cin.ignore(); But if you also type other characters that won't necessarily work either because it will only remove a single character. You need to study this thread to get a complete answer.

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

for(;;) is just one way to create an infinite loop. Another way is while(true) or while(1)

After cin >> choice; you might want to add a series of if statements or a switch statement and a series of cases.

cin >> choice;
if( choice == '4')
   break;
else if( choice == '1')
   do_something();
else if( choice == '2')
   do_something_else();

The break statement where you have it will cause the infinite loop to exit regardless of the value of choice.

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

I didn't realize VC++ 6.0 even supported fstream.h.

You will most likely have to make several code changes during the port from 6.0 to 2010 compilers because 6.0 was not very compliant with c++ standards and allowed a lot of non-standard coding. So just fix the problems one at a time, such as change #include <fstream.h> to #include <fstream> (Drop the .h extension). Then you will most likely have to add the using statements.

The second error you posted I would ignore for now. Fix the fstream.h problem and that second error will probably go away.

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

It doesn't matter if the dlls are static or not. The application program has to initialize the MFC library. Create a console program that supports MFC and you will see how that is done. I was able to do that with VC++ 6.0, but I don't know if that option is still available in more recent versions of the compiler.

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

Just buy a 3d laptop and you will be all set :)

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

MFC DLL requires and MFC application to call it.

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

I watched it on Blue-Ray DVD just a couple days ago -- awesome movie even without the 3d effect. In the WalMart store where I work they were selling like hotcakes.

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

Your Read() function does not need an ofstream object because that is intended to write something. Read() function should only use ifstream to read the data.

After opening the file you have to add a few lines to read each of the numbers in the file. Opening the file doesn't do that for you -- you have to write it yourself. Use the >> operator to do that.

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

What are you talking about??? c++ is a language.

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

what's wrong with it, or are we supposed to guess?

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

Yes I know. Its done very similar with normal arrays. Instead of using an erase() method I would just mark the array element as deleted, for example by replacing the number with 0, then when displaying the array ignore all elements with 0.