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

Getting "technical" is an absolute requirement in software development :)

jonsca commented: Props on your new avatar +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Does it matter which one?
No. You can use either, but integers are most common. If you use char then the compiler will have to take the time to promote it to an integer before its used as the index into the array. So you can speed up a program by a few nanoseconds by using ints instead of char.

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

>>Does this mean that int and char are not objects?
Yes -- they are not objects. They are data types. A string is not an object either. It is a c++ class that is defined in <string> header file. Objects are an intstance of a data type or c++ class

int x; // x is an object
std::string name; // name is the object
char address[255]; // address is an object
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

To change the time on your computer is operating system dependent. If you have a modern computer then you will have to use a modern compiler so that it can access os api functions. On MS-Windows you will use SetSystemTimer()

As for the batch files, call system() function.

abhijeet kamble commented: good +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For MS-Windows GUI then www.codeproject.com is a wealth of free code, libraries, DLLs and tutorials. Probably the largest repositories of code on the net.

Lusiphur commented: Thanks for the reference link :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

As for being your equal -- thank God that I am waayyy above that. You have shown us all very clearly that you are nothing but an arrogant asshole who is acting like a 10-year-old spoiled brat. Go back home to your mommy and leave the programming to us big boys and girls.

As for deleting your accout -- Dani does not allow that under any circumstances. If you no longer wish to be a member of DaniWeb then just stop posting.

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

You should be aware by now that you can only put executable code inside a function. push_back() is executable code. vector<string> words is just an object declaration and can go either inside a function or globally outside a function.

Think about what you are doing, instead of just randomly tossing ink at a piece of paper and hoping something useful will result. Much like the infinite monkey theorem

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

5.6 is not talking about returning multiple values but coding multiple return statements

if( condition1 )
   return 1;
if( condition2 )
   return 2;
// etc
crapgarden commented: great answers! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

6 hours? OMG next time use google! Here is how to do it.

wchar_t wname[255];
std::string name = "John";
size_t convertedChars = 0;
mbstowcs_s(&convertedChars, wname, sizeof(wname)/sizeof(wname[0]), name.c_str(), _TRUNCATE);

IGUIEditBox* player = env->addEditBox(wname, rect<s32>(170, 80, 320, 100));
cwarn23 commented: Life saver +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Use [code] ... [/code] tags -- they will add line numbers for you so that you don't have to do it yourself.

You said the function returns just a single character yet you are trying to return a character array. You can't have it both ways. What you should have done is char* getEmpName()const -- notice there is a * after char to indicate it will return an array of characters.

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

LOL :) Yes I can do it, but I won't. And I doubt anyone else he will do your homework for you either.

jonsca commented: Sure, sure, we all know you're just ironing out the basics now, AD +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The c++ compiler/IDE in the article is no longer recommended -- Dev-C++ too old and obsolete. Either of the following free compilers/IDEs are now recommended
Code::Blocks with MinGW compile
VC++ 2010 Expess

Here is a tutorial for introduction into MS-Windows GUI programming using pure win32 api functions.

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

"a" is a pointer to the letter 'a', it is not c++ class std::string. You can only use the + operator on std::string

std::string a = "a";
std::string b = "b";
std::string c = "c";
std::string text = a+b+c;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you know how to READ? I assum you do since you know how to write (this thead). Read the DaniWeb Rules, which you should have done when you joined.

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

>>How this while is executed?
Its an infinite loop because fgets() never returns EOF. fgets() returns NULL when it reaches end-of-file

tux4life commented: Exactly :) +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if you are using read() to read the data, then immediately call gcount() to get the number of bytes that were read. tellg() will only tell you where the file pointer is, not how many bytes were read.

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

5.2: Every c++ statement ends with a semicolon. Commas are only used to separate multiple statement on a line.

For example:

int a;
int b;
a = 0;
b = 1;

The above could also be written like below. Which one to use is up to you -- the compiler doesn't care.

int a, b;
a = 0, b = 1;

Double quotes are used to enclose strings, single quotes are used to enclose a single character

string World = "Hello World";
char c = 'H';

The compiler treats everything within double quotes as a null-terminated string, or character array. So that second statement char c = "H"; is wrong and will produce a compiler error message.

>>*what is the difference between these?
The first is a numeric value 64. The second is syntax error because you can not have two or more characters within single quotes.

A string literal is a set of characters within double quotes, such as "Hello World". A string object is just the name you give to the array string World;

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

#1: The use of variable i is not the problem. The problem is that you failed to use { and } to surround multi-line if statement

for (int i = 0; i < gameLibrary.size(); ++i)
{
        counter = i;
        cout << counter << "-";
        cout << gameLibrary[i] << endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Look carefully at those while loops. See anything strange (wrong) with them?

Take the first set of while loops. The first thing that will happen is that inFile6 will read the entire file while inFile3 and inFile4 remain constant (they won't read any more. After inFile6 reaches end-of-file the inFile6 loop exists and control returns back to inFile4, which will read the next record. The inFile6 will again attempt to do more reads, but it can't because its at end-of-file. The program will go back to inFile4 and read another record then repeat the error all over again. That will continue until inFile4 reaches end-of-file. At that time control returns back to inFile3, which read the next record .

In other words, your program is just a big f**ked up mess :)

jonsca commented: It's great when one can use the technical terms +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Actually, the loops in both code snippets are wrong. Why? Because eof() doesn't work like that. It only detects eof-of-file AFTER an attempt has been made to read the last item in the file, so the last item will get processed twice.

A better way to code it is like this, which will exit the loop upon end-of-file and will not process the last item in the file twice.

while( fin >> next )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry to hear that. Please give it my sympathies.

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

If you don't want to do it in Excel or as a CVS file as previously mentioned, then I'd go with VB.NET because I think it has built-in support for Excel files. But then I could be wrong because I don't know a whole lot about vb.NET.

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

I'm confused. You want a std::list of matrices -- each node in the std::list contains a different matrix? Something on this order?

#include <list>

class matrix
{
public:
   matrix(int rows, int cols) 
   {
      data = new int*[rows];
      for(int i = 0; i < rows; i++)
         data[i] = new int[cols];
   }
private:
   int ** data;
};

int main()
{
    std::list<matrix> matrices;
}

>>There is no my matris define. Is there any way to get a value on a matrix in a list exactly like "matx[3][4]"

Using the above code -- the answer is no because the variable matrices in main() is not a 2 dimensional array or list.

If on the otherhand you don't really want that std::list then you can write an overloaded [] operator to do what you want with must the c++ class I posted.

int main()
{
   matrix matrices;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have this feeling that not having english as my main language makes me miss important points when reading these books.

I look up the new words ofcourse, but still.

Annoying! >:(

English IS my first language and I still look up some words too :) For example, do you know the longest word in the English language? (hint: it has 189,819 letters)

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

>>mods / featured posters / sponsors /team colleagues etc etc etc are just as prepared to give crap answers as noobs

Yup, I do that on occasion too. Just shows that nobody, even Narue, is above giving crap or wrong answers on occasion. All that my post count means is that I've probably given out a lot more crappy answers than almost anyone else here.

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

If you want to initialize the array to 0 then just declare it like this: int prime[200000] = {0}; and the compiler will most likely use the optimal way to initialize it.

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

>> On a linux platform you will learn more as you have do all work on your own

Not if you post your questions here on DaniWeb :) There are a lot of expert *nix programmers here ready and willing to answer questions (No, I'm not one of them).

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

That was three years ago -- the mixture may have changed since then.

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

The problem is that vc++ uses UNICODE strings by default. You have to go to project settings and change it. Select menu Project --> Properties (the last menu item in the list) --> Configuration Properties --> General. Then on the right sice of the screen, near the bottom of the list change "Character Set" to "Not Set".

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

That may be compiler implementation dependent. On VC++ 2010 Express fstream only includes istream. If you want cout then your program must include <ifstream>

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

1. You must be compiling that program as c++, not C because C requires the keyword struct before each use of the structure name, such as struct mystrut . Change the file extension of the program file to *.c

2. >>(first+1)->number
You can't access members like that because its a linked list, not an array. The correct way is first->next->number Its a lot simpler to use a loop

struct mystruct* node = first;
while( node )
{
   printf("%s\n",node->name);
   node = node->next;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>And BTW the posts are going way off topic

Not really -- the op didn't ask a reasonable question in the first place.

nbaztec commented: LMAO! :D +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>If anyone has the actual code would they be able to paste it in?

Nope -- not happening here at DaniWeb. We don't do people's homework assignments for them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ketsuekiame commented: I'll have to bookmark that one :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Microsoft decided to hide that menu on you thinking that programmers are too dumb to know how to use it. To activate the Build menu click on Tools --> Settings then select Expert.

jonsca commented: Good one, I hadn't stumbled onto that yet +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One more hint: you will need to know 4th grade math (add, subtract, multiply, and divide). What firstperson posted (except for the mod operator) was nothing more than what a 4th grader would learn in most USA schools.

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

>>it possible to call millions of functions by specifying strings in command line arguments? I think no

And why not? Just extend the example I posted to include several million methods in the classes. Of course the methods have to be known at compile time and your compiler may put a limit on the size of the executable.

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

Use a different compiler and come into the 21st century. That compiler can not be used to access win32 api drawing functions.

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

And for god's sake format your code so that we can read it! No one is going to read all that unformatted crap.

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

string literals such as in your second code can not be changed because the compiler probably puts string literals in read-only memory.

The first example is making a copy of the string literal which the compiler places in read/write memory, so there is no restriction on writing to that memory location. However ... the first program still will not work correctly because there was not enough roon allocated for the first string to hold the second string.

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

Example:

#include <iostream>
#include <string>
#include <Windows.h>
using std::cout;



BOOL CALLBACK MyEnumProc(HWND hWnd, LPARAM lParam)
{
    char title[500] = {0};

    GetWindowText(hWnd, title, sizeof(title));
    if(strstr(title, "Notepad"))
    {
        HWND* windowHandle = (HWND*)lParam;
        *windowHandle = hWnd;
        cout << title << '\n';
        return FALSE;
    }
    return TRUE;
}

int main()
{
    HWND windowHandle = 0;
    EnumWindows(MyEnumProc, (LPARAM)&windowHandle);
}
Kesarion commented: Great example ! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on the file and its contents. CFile is not a good choice for reading strings (standard text files) unless you also want to use CArchive and CString. If you don't have to serialize MFC classes then I would use standard c++ fstream

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

You can use the registry functions for *.ini files. See this link, then scroll down the page until you find GetPrivateProfileInt() and etc.

Or you could just write your own functions to read/write/update the *.ini file. Since *ini files are just text files you will have to rewrite the entire file in order to change anything. If you have a lot of changes to be made at one time then it will be a lot faster to do it yourself rather than use the win32 api registry functions.

Rajesh R Subram commented: Perfect answer. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We are not here to write your program for you, but we will help you if you show some effort, such as post the code you have already written.

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

I can't even get Turbo C to install on 64-bit Windows 7, let alone try to compile anything with it. There will come a day when India's universities will be forced to upgrade their school's compilers and teaching. They are putting their students at a huge disadvantage by teaching with such old tools.

jonsca commented: N/A +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I require complete and tested code snippets please!

Thank you.

Are you kidding??? You've been around just as long as I have and you can do that yourself. Besides, I don't have time to do it -- I'm playing Tourchlight game :)

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

You are using Trim() incorrectly. None of the Trim overloads take a CString parameter. Nor should the parameter be an array of strings -- only one string that contains the characters you want it to use for trimming. See this example for how to use Trim() correctly.

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

Input redirection is done at the command-line level, not from within a C program. If you want to redirect a file into the C program then the C program will want to read the data from stdin. You can still use Aia's example, but replacing file_handle with stdin.

There are ways to write your c program to get the data from either stdin or a file.

int main(int argc, char* argv[])
{
   FILE* file_handle = NULL;
   if( argc > 1) // file specified on the command-line
   {
       file_handle = fopen( argv[1], "r" );
       if( file_handle == NULL) // can't open the file
       {
            printf("Error\n");
            return EXIT_FAILURE;
       }
    }
    else
       file_handle = stdin; // assume file was redirected

    // now do all the reading
}

}

Aia commented: Very proper. +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

FOUR: If you want your code to be portable across operating systems and even compilers then don't do it in assembly. Assembly language is not portable. And inline assembly may not be portable between different compilers. Most C and C++ compilers today are smart enough to do a better job at producing assembly code than the majority of human coders.