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

with that compiler, as well as g++ and gcc, I think you have to add -Wall so that it will produce better warnings.

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

Welcome to DaniWeb. Ohhh how I loved Tucson when I was there for three years during the 1970s. I hope the city is just as great now as it was then.

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

1. There appears to be a huge memory leak in that code -- when are p and pp deleted

2. Suggest you declare p, pp and wcstring higher up in the program, up above the beginning of that while loop. That way they are allocated just once during the lifetime of the program instead of on each iteration of that while loop. That will make your program run a bit faster too.


3. Are you sure there is enough roon left in wcstring to add that additional amount of characters on line 20?

3. That while loop is constructed incorrectly because eof() doesn't work that way. This is how to write the loop while( getline(inFile1, line) ) 4. Use your compiler's debugger to find out what is causing the program to crash. Other than the above comments your program looks normal to me.

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

That problem might be your compiler. vc++ 2010 express gives this warning, which is why I never let warning slide because they are normally actual errors.

error C2040: 'f' : 'double *()' differs in levels of indirection from 'int (void)'

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

A few problems:

1. There are more than 400 items in players.txt, so you need to increase the size of those two arrays

2. Add the ios::biary flag to the two binary files

3. When reading/writing binary arrays the arrays can be read/written all in one shot -- it is not necessary to write or read them one array element at a time. But sometimes it is more useful to read them one at a time if you don't know how many were written.

4. Move the class plr up above main() so that you can write other functins that use the same class. Almost no programmer will put the class definition within a function because it limits its scop to that one function. Not a very useful thing to do.

5. Instead of that array it would actually be better to use either std::vector or std::list so that you don't have to know how many items are in the files. Buth vector and list grow as you add items to them.

#include <fstream>

#include <iostream>

using namespace std;

  class plr
    {
    public:
      int id;
      int shirt_no;
      int age;
      int goals;
      int pos;//0-GK,1-DEF,2-MID,3-ATT
      char LName[51];
      char FName[51];
      int team;
      int skill;
      int goaltime;
      int cards;
      void transfer(int t_id)
      {
        team = t_id;
      }
      plr() 
      {
          id = shirt_no = age = goals = pos = 
              team = skill = goaltime = cards = 0;
          LName[0] = 0;
          FName[0] = 0;
      }
  };

int main() …
anantk commented: thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Secondly will VC++ 2010 compile programs written in C?

Yes -- it compiles *.cpp files as c++ and *.c files as C.

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

Post the newes code attempt because I can't see your monitor.

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

That may be some compiler-specific extensions to the c++ standards. None of the compilers I know about allow that kind of constructs.

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

The first works ok because L converts a string literal from char* to wcar_t*. The second doesn't work because it is attempting to pass char* to a function that expects wchar_t*, and typecasting will ont convert that either.

Read this article

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

>>Turbo C can display only 16 colors so I will need to use a Windows Interrupt[or something like that] to display the image.


Not with that compiler you won't. That compiler can not access any of the win32 api functions. Get a 32-bit compiler such as either Code::Blocks or VC++ 2010 Express both are free).

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

You can also make SIZE char like this: char c = SIZE; Or a double like this: double d = SIZE; Or you can use defines to construct strings, as in this simple example.

#define SIZE 65
main()
{
    char p[] = {SIZE,'p','p','l','e','\0'};
    printf("%s\n", p);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The extern keyword only tells the compiler that the variable will be declared later. It's common to declare variables using extern in header files. Then in one, and only one *.c file the variable(s) have to be declared again but without the extern keyword.

The compiler does not complain about the difference between int and char in your program most likely because data type char is an integer -- but only one byte. So int and char are really both integers.

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

arrays are always, always indexed beginning from 0, never 1. So line 38 should be for (int i=0;i<401;i++) .

The index values on lines 41 and 42 should be using the loop counter i, not the value of j that was read from the file. What would your program do with a value when j == 500? (Hint: crash!) The value of j should the used as the player's ID, not the index value into the array. You should assume the player's ID has no relationship to the index value used in the array.

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

Post the changes you made.

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

Sounds like what you want are tutorials. There are lots of sites that have them, such as DaniWeb, and Dream.In.Code

As for practicing -- just do it on your own computer with your own compiler. Unless of course you don't have a computer of your own.

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

Delete that do loop on line 152. Why would you want to continuously read the same file over, and over, and over forever???


change the loop starting on line 64 to this:

while( MySimpletron >> instructionRegister )
{
    memory[size] = instructionRegister;
    cout << setfill('0') << setw(4) << memory[size] << "    ";
    ++size;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I uderstand your problems -- I worked for US gov for quite a few years. You mean you have not installed any of the service packs for that compiler (there were 6 of them)???

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

Oh you poor boy. It must be tough having to put up with sooo many holidays. :)

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

That was a common problem with that compiler and the only fix is to reboot the computer. Unfortunately there is another common problem -- when you try to save a file the IDE thinks the file is already open by anothe program and can't save it. That can resut in complete loss of the program unless you pay attention to the errors and save it as a different file name before closing the IDE.

After some experiementation and talking to other programmers it seemed that I needed to turn off running antivirus programs, such as Norton Antivirus. That, at least solved the prblem on my computer which was running Windows XP. I have not experienced any of those problems with later versions of the compiler/IDE.

This is a good reason why you should upgrade your compiler to VC++ 2010. Version 6.0 is full of bugs.

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

write a program that parses a *.cpp file and extracts all its symbols. Your program will have to recognize valid symbol names, which may be easier if the *.cpp file is formatted so that symbol names are surrounded by spaces int example = 0; instead of this: int example=0;

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

You will have to rewrite the entire file. Rea the original file into memory, append the data in memnory, then rewrite the file with the new lines.

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

I suppose ther are as many ways to write a logger as there are progammers. The way I did it was to write a funtion that took a const char* as parameter (the message to be logged), open the log file, write out the message, then close the file. Its a very simple function. Then you can call that function as many times in your program as you want to.

If you only want to do the logging when the program is compiled for degging then you might do something like this:

void log(const char* message)
{
#ifdef _DEBUG
   // code to log messages go here
#endif
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

%ls also works (see this man page) swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%lsY", L"AMEDA");

N1GHTS commented: extra credit! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what eactly do you mean by "using events"? c++ is not event driven.

NicAx64 commented: may be signal driven (posix signals) :) +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

On Ubuntu with Code::Blocks it's like below. Apparently MS-Windows and *nix work opposite because Ubuntu worked like Nights mentioned.

For some unknown reason CB could not find the function prototype from wchar.h for swprintf(), so I just manually copied it into the C code. I have not bothered to figure out why that happened, must be some wort of #define problem.

#include <stdio.h>
#include <wchar.h>
#include <string.h>
extern int swprintf (wchar_t *__restrict __s, size_t __n,
		     __const wchar_t *__restrict __format, ...);

int main()
{
    wchar_t buf[255] = {0};

    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%SY", L"AMEDA");
    printf("%S\n", buf);
    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%sY", "AMEDA");
    printf("%S\n", buf);
    getchar();
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Acient Dragon's advice was correct, only it was backwards (%S corresponded to wchar_t while %s corresponded to char).

It depends on whether you use sprintf() or swprintf(). The usage of %s and %S is reversed for each of those two functions. I tested the code I posted using vc++ 2010 express so I know it's correct for swprintf(). If you use sprintf() you will get the opposite results.

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

download and use this dependency walker to find out what dlls and libraries your program needs

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

I don't think you can use that code to update a file on some other computer. You might have to use Windows RPC to accomplish that.

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

I don't know the answer to your question. But I am putting myself in into this for learning purpose.
I have not seen this function used in any c program that I have come across in my short experience with C. Can you brief about what exactly is the purpose of wide characters. I referred Google and now know what is wide characters but if you can give some examples where all this is used in real life, I would be grateful.

Wide characters wchar_t is used in UNICODE programs, which may or may not be English. Some character, such as Chinese, will not fit in one-byte char, so they use wchar_t. The sizeof(wchar_t) is not consistent among operating systems -- MS-Windows sizeof(wchar_t) == 2 while *nix its 4. So you have to be very careful about transferring unicode-witten files from one os to another.

sree_ec commented: Thanks... +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Depends on the operating system. MS-Windows use Windows Hooks.

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

you are seeing the difference between %s and %S (not the capitalization os s and S).
with swprintf():
%s assumes the parameter is a wchar_t*
%S assumes the prameter is char*

The rule is just the opposite with sprintf()

This illustrates the difference

int main()
{
    wchar_t buf[255] = {0};

    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%sY", L"AMEDA");
    printf("%S\n", buf);
    swprintf(buf, sizeof(buf)/sizeof(buf[0]), L"G%SY", "AMEDA");
    printf("%S\n", buf);

}
N1GHTS commented: This answer saved me long hours of trial and error +1
sree_ec commented: I dint know that %s and %S existed :D +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You are burying yourself a little deeper -- that was not pseudo code.

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

O,I'll give you that one, but it still contains syntax errors.

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

The code you posted doesn't compile. You should at least compile and test it before attempting to post it as an example of how to do something.

Sorry, but that will not work for an array that contains random numbers, where duplicates can appear in any order throughout the array.

Test your code with this array
1 5 6 1 2 5 4 3 1 7 6

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

Don't post something just becaue you might think it might be useful to someone some day. I was going to answer the question, but now I'm glad I didn't wast my time on it.

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

Here is the future of computers, or is it the present? I think we are already living in the world of sci-fi gadgets.

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

Sleep() only works for the current thread, it does not affect other threads. So if you think other threads are also sleeping then you are doing something wrong or you do not understand the code you wrote.

If you put that same Sleep() at the same place in the code for each thread then each of them may sleep at the same time and confuse you, the programmer. If that is the case, then maybe call Sleep() with a different parameter value for each thread so that they are not all simultaneously sleeping for the same amount of time.

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

1. move line 20 so that it increments i after line 22.

2. line 31: There is no need for that j loop. Just make the tests for minimum and maximum within the i loop that starts on line 19. Every time a new number of entered check of the new number > max and check if its < min.

3. When i == 0, both minvalue and maxvalue should be set to input. Since inputs can be negative, the values initialized on lines 11 and 12 may or may not work. So just initilize those two variables for the first keyboard input value.

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

Read through the threads on this forum and you will find hundreds of programs you can code.

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

did you see this video tutorial?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <iostream>

int main()
{
   while(true)
   {
      std::cout << "Read previous post\n";
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read this link and you will see that none of the overloaded functions take two integers.

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

GetWindowText() returns an int, which can not be typecast to char* or LPCTSTR. Read all about that function here instead of just blindly tossing code at your compiler and expecting things to work.

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

fflush(stdin) is non-standard and not supported by many compilers. fflush is used to force the operating system to write everything to the output stream. Since stdin is an input stream and not an output stream fflush(stdin) may or may not work, depending on what comiler you use.

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

>>sum = number + number

It should be sum = sum + number;

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

You need to read a tutorial or book about how to write for loops. The for loop has three parts
1. The sttement that initializes the loop counter and/or other variables

2. The test for a condition which will terminate the loop.

3. Increment or decrement the loop counter

Any or all of the three parts are optional and may be replaced with just ; character

For example if you want to enter a certain quantity of numbers

int num = 3;
for(int i = 0; i < num; i++)

The above for loop
1. Declares and initializes a loop counter i. If you need to use the value of the loop counter later on in the program, outside the loop, then you will have to declare the variable before the loop starts.
2. Checks if the value of i is less than the value of num. The
loop terminates when this condition is true.
3. Increments the loop counter.

Now you should be able to change your program so that it meets the above requirements.

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

what compiler are you using? what operating system? what are the error messages?

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

>>I heard IE9 has issues with many sites
Probably because it hasn't been released yet.

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

Your avatar looks ok to me.

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

So, you want to send something to a printer?

What operating system? Is the printer connected directly to your computer or is it located on a network? Lazer printer or line printer?