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

Thank you for the vocabulary lesson :), but I actually understand what the word demand means in this thread...

Maybe if you cared to read my post well enough you would have noticed I mention your specific usage of the word in the first part of my sentence, and that the second mention between the double quotations has nothing to do with what it implies in your post or anyone's at all, intentionally.

Thanks again though.

[offtopic]
If I insulted you I am truly sorry -- there are a lot of members here whose mother thoung is something other than English, and English has a lot of suttle differences that they may or may not understand.

On the otherhand I've come across many people whose mother toung is something other than English who write English better than native English speakers. Propably because they have to study it more intensly. I know many native English speakers who can not put two words together to make a comprehensible sentence, and its getting worse with texting so widly used now.
[/offtopic]

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

>> I'm not even to be considered an active user yet to have the right to "demand"...

I think you misunderstood the use of the word "demand". Nobody said or implied that you are demanding anything. Use of the word demand means something else entirely, such as "a large demand for katsup" means that there are a lot of people who want to buy katsup. That is the way the word demand is being used in this thread.

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

Why not? You see child windows with buttons etc. all the time, just look at your browser to see them in action. If you use FF or IE7/8 each of those tabs are just child windows.

You might want to investigate either CLR/C++ (Midrosoft Forms) or C# which will make you a lot more productive than using win32 api functions directly.

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

There is no reason for such a forum. How may people have posted questions on DaniWeb about mobile? I suspect next to 0. Dani won't add new forums unless there is a clear and large demand for one. One person (you) does not a large demand make.

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

Easily done with SQL.

SELECT Username,Name,Login.Group,Groupname
FROM Login, Group
WHERE login.Group = Group.Group

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

First, do no use two different loops to calculate the minimum and maximum values -- do that all in the same loop. When the program gets to that second loop to calculate the minimum value the file pointer is already at end-of-file so the loop don't do anything. Just combine both loops by putting the if statement in the second loop after the if statement in the first loop. Don't forget to move the other two lines as well into the first loop.

Other than that, I don't see offhand what caused the seg fault.

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

>>can u rewrite the code...
Yes I can -- but I won't. You will never learn how to write programs if other people do your work for you. Post your attempts to solve it then ask questions. I already gave you a couple hints.

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

Probably because that code prints the EOF character. Try this one. Variable C needs to be int, not char.

int c;
while( (c = getchar()) != EOF)
   putchar(c);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first problem is that you are attempting to use unallocated pointers -- can't do that. You have to allocate space for all the characters you want to put into them. Declare them something like this: char str[255] = {0}; ; You can replace the value of 255 with anything you want, as long as its large enough to hold all the charcters you want to put into that string.

Second problem is your use of the function gets(). Don't use gets() for anything -- ever. Use fgets() then remove the '\n' that fgets() adds to the end of the string.

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

Use VC++ 2010 Express and it has a toolbar that contains all available standard controls. Go to www.codeproject.com and they have lots more of them. Of course these are for GUI programs, not console programs.

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

You can't keep the user from typing on the keyboard but you can remove all remaining keys from the keyboard input buffer. If you are using c++ cin then read this thread to find out how to flush the input buffer.

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

You could try Sane's Monthly Algorithms Challenges which are designed for people of all programming levels.

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

When entering integers the '\n' (Return key) is left in the keyboard buffer. You need to clear that and all other characters out before calling getline(). See this thread for instructions how to do that.

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

"aligned" is the key word -- what alignment? Not all compilers use the same alignment factor, and some compilers have options to change the alignment. Microsoft compilers have a #pack paragma what lets you align different parts of the program with different alignment factors.

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

So i will use something like CALLBACK WaitCommEvent()?

Yes you can use that, but put it in another thread so that it doesn't block the main program.

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

When you open the com port with CreateFile() you can specify a callback function that MS-Windows will call when data arrives at the port. That way you don't have to keep polling it to find out if there is data.

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

I would make table a vector instead of array of strings so that it can hold as many strings or as few as you want. vector<string> table; . IMHO that hash line is probably much less efficient than just adding the new string to the next available slot in the array. For example if you input two strings that are the same length then that hash function will produce the same array index and the second string will overwrite the first.

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

The way to communicate through com1 will depend on the operating system. MS-Windows, use CreateFile() to open the com port, then ReadFile() and WriteFile() to read/write to it. See commuications functions for more details.

I don't know a thing about ladder logic because I never programmed a PLC.

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

>> grid[j] =='.';

You used the wrong operator. Use the = operator, not the boolean == operator. grid[i][j] = '.';

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

You need to initialize the array with all '\0' before doing anything.

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

Move line 25 out of that class. srand() should be called only one during the lifetime of the program. I normally put it near the beginning of main().

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

>>page 1->Show(this);
Remove the parameter. Just this: page1->Show(); I created a Forms application that contained two forms and this worked for me

private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
    Form2^ f = gcnew Form2;
    f->Show();
         }
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>visual C++ 2010 Express edition, which is a trial one
No it isn't. Its free to use for as long as you want and you can use it for both commercial and non-commercial purposes. There's nothing trial about it, at least not in the sense that the trial period expires.

What exactuly to you mean "from one page to another page" ? Do you have a Forms application that contains a button? Your question is very ambiguous.

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

Then most likely what you want is this: void display(employee &emp,double pay,double nysTax,double fedTax,double netPay){ Since structure employee contains a several arrays and two doubles you only have to declare the employee parameter once. That is going to pass a reference to the entire structure, not just a given member variable.

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

>>// Why do we need to return a reference
That isn't returning a reference, but a complete duplicate copy of the class. If you want it to return a reference then you need to change it like this: rational& operator= (rational num)

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

The function prototype is incorrect. The first three parameters should be char*, not employee. The first three parameters in the function implementation are also incorrect. Change them to char* instead of employee.

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

The procedure for submitting tutorials is to PM Davy (Happygeek) with the tutorials. There is no other way to do it at the present time.

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

@Joey: I was thinking indexes as Adak suggest would not be allowed either. If its ok, then that is the best way to go.

@Adak: I think you've overcomplicated the program. Just copy the contents of arr1 into arr3, then the contents of arr2 into arr3 where arr1 left off. Two integers are needed, one for arr1/arr2 and the other for arr3. No need to check of the length if arr1 and arr2 are the same or different.

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

>>read two arrays of chars
Read them from where? the keyboard? a data file? sockets? serial rs232 port?

I know of no way to do that assignment without using either pointers or fucntions in string.h. Maybe you misunderstood the assignment. If not, then you should get a different teacher.

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

line 22: drop the gets() because its very buggy. In c++ programs you should be using cin.getline()

>>Then you should do the reading with the >> ifstream operator instead of .read and the << ofstream operator instead of .write

The file is a binary file, not a text file. So read() and write() are appropriate functions for binary files.

The last loop is incorrect. And use c++ cin.get() instead of getch()

while( f2.read((char*)&e,sizeof(emp)) )
{
 cout<<e.desig<<"  "<<e.name<<"  "<<e.sal << '\n';
}
f2.close();
cin.get();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Post the code You wrote. Nobody here is clairvoyant. My guess is to put the code you need in the form initialization function.

BTY: That looks like a very good youtube tutorial :)

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

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

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

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

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's wrong with it, or are we supposed to guess?

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

>>A colleague advised me that I should store string pointers for efficiency

There is no efficiency gained by declaring pointers to std::string objects. In fact it will be less efficient because you have to allocate memory before it can be used.

It's somewhat different with C style character arrays. With them you have one of two choices
(1) declare the arrays to be a fixed size, which needs to be large enough to hold the longest string you might want to copy into it. That can waste a lot of memory of there are a lot of strings.
(2) declare a char pointer and allocate memory so that its only large enough to contain a specific string. Example: Note that you still have to duplicate the string. Somewhere in your program, either here or in the read() function new memory has to be allocated for each string read from the file.

struct node
{
    char* data;
    struct node* next;
}

void add(const string& d)
{
    struct node* newnode = new struct node;
    newnode->data = new char[d.length()+1]
    strcpy(newnode->data, d.c_str());
}

The std::string c++ class avoids making you, the programmer, deal with both the above two problems. So if you are using std::string then you don't have to worry about efficiency.

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

>>head->data=&s;

That's the problem. Don't do that in a linked list. Instead, let the linked list own the memory for all strings by removing the pointer

struct sNode
		{
			string  data;
			sNode * next;
		};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You posted the wrong part of the program. The problem is with the two classes you have defined. Just declare the class destructor as virtual and the error will be fixed.

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

You have to pass to script_start a pointer to a pointer (two stars, not one) so that it can change it

int  script_start(lua_State **L)
{
	*L = lua_open();
	if (*L == NULL)
	{
		script_error(L, "%s", lua_tostring(L, -1));
		return -1;
	}

	luaopen_base(*L);
	luaopen_table(*L);
	luaopen_io(*L);
	luaopen_string(*L);
	luaopen_math(*L);
	luaopen_debug(*L);

	return 0;
}

And see the two changes here too

int main(int argc, char *argv[])
{
	lua_State *L = NULL;
	script_start(&L);
	script_end(L); //error here (accces violation)
	return 0;
}

>>script_error(L, "%s", lua_tostring(L, -1));
When *L == NULL how do you possibly expect that line to work??

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

You just need to add the commas outFile << s1 << ',' << ss << ',' << p << endl One problem you might encounter is if the text filed contains a comma. In that case you have to enclose it in double quotes.

For example: 1997,Ford,E350,\"Super, luxurious truck\" The backslash \ goes in your c++ program, not in the file itself.

Here is more about those csv files.

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

You can view the comments of the rep you have been given by looking in your CONTROL PANEL (see the link at the top of every DaniWeb page)

You could also do it your way, but press your browser's Back button or just clicking anywhere outside the rep box when you are finished reading the comments.

VernonDozier commented: Here's some "rep". It won't count, but thanks. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

link doesn't work

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

Yes you could use a vector of structures. The structure just has two members: string extension and int count.

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

>>then I free (x); and i'm fine? and will not have a memory leak?
Yes, that's the way to do it.

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

The macro NULL is intended for pointers, not integers, Instead of casting NULL to int why not just pass 0? It would make more sense. Example: line 11 should be like this: if ( numOfArrays == 0 && sizeOfEachArray == 0) Remember: integers are not pointers (normally) so using NULL for them is an inappropriate use of that macro.

>>I can't free stringArray2 from main
why not?

>> makeString ( (int)NULL, (int)NULL );
The string can not be free'ed that way. Make another function to free the array void FreeString(char **string, const int numOfArrays, const int sizeOfEachArray )

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

You can't make the return value of that function anything other than an integer. Why? Because they are not normal functions -- it acts more like a self-contained process than another function, except that threads have access to all global data in the entire program. So when a thread returns it just goes back to the operating system much like any other program would do.

The code you already put on line 30 should be sufficient. The return value on line 31 is meaningless.

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

The value of A is 60, yet you have a loop that assumes its 600. Change that loop like this: for(i=0;i<A;i++)