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

The first thing you need to do is check your computer's file system and see if the file name you enter is in the same directory as where your program is running. If it is somewhere else then you need to specify the full path to the file, such as c:\Prograzm Files\somethere. If the path and/or filename contains spaces, as I posted, then you can use the >> operator of cin, but you will have to use getline().

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

>>I'm not doing this inside any operating system

Oh! :-O Then how are you running that program?

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

You will probably have to do things a lot differently when porting from C to CLR/C++. Microsoft has made a lot of things much easier to do. Here is a tutorial for C#, which is a very close relative of CLR/C++.

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

For this to work, you'll have to inspect each character from the stream using the isdigit() function.

Also you will have to get the input as a string and not as numeric data. If the valid checks pass (e.g. no non-digits entered) then you can easily convert the string to long.

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

The difference depends on the compiler you are using. Some compilers treat them the same, while others don't. With vc++ the <> tells the compiler to only look in its standard include directories (there are options to add to the list of directories), while the "" tells the compiler to first look in the program's source directory, it the header file is not there then the compiler will look in its standard directories just as if you had used <>.

I think google made a recent change to its search algorithms because some things seem to be more difficult to find than previously.

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

The short answer it No -- not with scanf(). scanf() will stop processing keyboard input when the first non-digit is reached or when no more charcters in the keyboard buffer. That function does no error checking.

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

Won't help. If you are converting from big to little endien (or vice versa) you will just simply have to rewrite the order of the bytes. typecasting will not affect that.

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

ShellExecute() or CreateProcess(). Which to use depends on how much control you want over how the new process is created. Once the program is compiled it doesn't matter what language it was originally written in. The original language is lost in *.exe programs.

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

>>long some_long = (long)&foo[6];

I think that's called undefined behavior, typecasting an address into a long integer. The two may or may not be the same size, depending on the compiler you are using.

The way I would do it is like this: long some_long = *(long *)&foo[6];

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

Just delete all the code previous to the line starting with POSITION. Its all useless code anyway.

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

>>So,question is,how do i set a struct to null?
In an array, you can't. One way to do it is to add a deleted flag to the structure and set it to true if the struct is to be considered deleted. Another option is to set the first byte of the key field string to 0 to identify it as a deleted struct. A third option is to move all the remaining structs up one slot in the array, overwriting the struct you want to delete. That will leave an empty struct at the end of the array.

>>So,to put it simple,how do i set myArray[index] to null?
You can't, unless myArray is an array of pointers, such as MyStruct* myArray[MAX_ROWS]; In that case you call malloc() to allocate each of the rows in the array, and free() to delete one.

IMO a better solution would be to use a linked list, not an array. That will let you actually delete the node in the list and will leave no unused nodes.

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

>>CPtrList& templateList =AfxGetApp()->GetFirstDocTemplatePosition();


That makes no sense at all. You need to do some serious reading if you intend to use MFC. Look up the functions you are trying to use and read what they return. In this case the function return POSITION object, not CPtrList object. You can't just toss random code at a program and expect it to work.

Yes, MFC is difficult to learn -- I'v read the average learning curve is about one year to learn it well.

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

>>It's also somewhat difficult to differentiate between a legitimate member making inane comments and a sig spammer.

I use post count and past posting history for that purpose. First time posters on PFO who make that kind of post get the post deleted, but not infracted or warned because there are no rules about it. If the poster has made otherwise useful posts in other threads then I'll leave it.

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

I can't open that zip file, but make sure the data file is in the same folder as the source files. Your program should also check to see if fopen() succeeded, which it is not doing.

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

I compiled and ran your program without changing anything and did not get that error. It ran and produced this output file

The number 550 was read in

Maybe there is something wrong with your input file? Attached is the file I used

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

That's a different problem. Which line is the error on? Post the exact error message.

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

In that case, use __int64 instead of int.

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

depends on the operating system. MS-Windows and VC++ 2010 have __int64 data type. Other compilers might support long long. VC++ 2010 allows long long but the compiler treats it as 32-bit long integer. If you are not sure what your compiler supports then just write a simple program to print out its size

#include <stdio.h>
int main()
{
   printf("sizeof(__int64) = %d\n", sizeof(__int64));
   printf("sizeof(long long) = %d\n", sizeof(long long));
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I get an error whenever I try to run it.
What was the error?

>>x = (int*)malloc(length*4);

what makes you think the size of an integer is 4??? Maybe it is, and maybe it isn't. The size of an integer depends on the compiler you are using. A more portable way to write that is x = malloc(length * sizeof(int)); And notice that C language does not require the typecast like C++ does. So if your source code file name has .cpp extension then you are writing c++ code, not c code.


line 42: Depending on the values you put in the two arrays, summing p like that could easily cause integer overflow. Might be better to use a 64-bit integer to reduce that chances of that happening.

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

what do you mean by "composition" ?

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

Sorry, I have no idea what you want.

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

If you use MinGW then this thread may help you. Go to project options, linker tab, and add -static flag. But that flag didn't seem to make any difference with my small test program.

>>tell me a way to link to the .dll files I need without having them directly in the same directory as the .exe file

If they are not in the same directory as the *.exe file then they must be on one of the directories in the PATH environment variable. On Windows 7 (probably earlier versions of Windows too) click Start --> Control Panel. Then select System icon. In there you will find options to view and edit environment variables, including PATH. You can add another directory to the PATH or copy the dlls into one of the existing directories. Adding your own directory is ideal so that you don't clutter up someone else's directories with your dlls.

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

The command-line compiler is cl.exe. In a command prompt window (DOS box), first run vcvars32.bat found in the compiler's install bin directory. That will set all the environment variables needed to run cl.exe

cl.exe uses many of the flags that are commonly found in make files. /I followed by include directory, and /L followed by library directory. So if you want to compile and link myprogram.cpp with mylib.lib cl myprogram.cpp mylib.lib -o myprogram.exe /L c:\mylibs This can all get very complicated if you don't use a makefile and nmame.exe utility.

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

>>What on Earth are you talking about? There are robust cross-platform libraries for everything in C++

Agreed, but the libraries are os-specific. If you are going to write a library then you most likely will have to use os-specif function calls. If you look at the source code for boost libraries I'll bet you will find os-specific functions. That is what I had in mind.

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

I don't think there is anything like that for c++ because c++ programs are pretty much operating system specific. Yes the language itself is os independent, but to make c++ programs do anything worthwhile they have to make os-specific function calls, and the programs have to be recompiled for each target platform.

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

Oh I give up too. I tried to help but all I got was shit. Let him solve the problem himself.

VernonDozier commented: Everyone here knows you're not at fault. +13
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I agree with Fbody that you probably have multiple copies of transinfo.txt. Suggest you search your hard drive and delete all of them except one.

And try being a little nicer, or you might find yourself banned for awhile.


>>thanks everyone else who's not a d-bag like A-Drag
I'll have you know I'm no d-bag. I'm an ass hole, or so I've been told. But did I post profaniy??? NOoooooooooooo. Now whose calling the kettel black.

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

Are you using MAC? I'm using Windows 7 and VC++ 2010 Express.

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

Looks ok for me (using IE8). Its a round white circle.

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

This is what I got when I ran your program. What's wrong with it?

0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
23503Receive 50 units of car 3
1Receive 75 units of car 1
0Receive 40 units of car 0
3Sell 25 units of car 3
5REJECTED: Insufficient Stock
6Receive 50 units of car 6
8Receive 300 units of car 8
3INVALID TRANSACTION CODE6
0Receive 30 units of car 0
2Receive 10 units of car 2
6REJECTED: Insufficient Stock
4Receive 30 units of car 4
6Receive 200 units of car 6
5REJECTED: Insufficient Stock
6Sell 100 units of car 6

0 70
1 75
2 10
3 25
4 30
5 0
6 150
7 0
8 300
9 0


Total potential income: 450000
Press any key to continue . . .
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Everyone will just ignore you when you use such cursing.

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

>>Am doing migration from 16 bit code to 32 bit... help me to solve the issue...
There were some very major changes to MFC between the two versions. Which 32-bit version of the compiler are you using? I hopt it will be vc++ 2010.


Look up the function GetFirstDocTemplatePosition() and you will easily see what the problem is. This should have taken you no more than 60 seconds to find the problem with your code. Once you get the POSITION returned by that function you have to call GetNextDocTemplate() to get a pointer to the CDocTemplate class in which the CPtrList object exists that you are looking for (there could be more than one CDocTemplate objects in the program). Once you get that, you can typecast it to your specific document class (CDocument is derived from CDocTemplate), such as CMyDocument, and that will let you gain access to the CPtrList object in the document.

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

>>I can't and I won't translate all of that into English because it's irrelevant. I
Then why did you post the link if its not relevant information? But let's not get hung up on that.

>>Why do I need it?
I have no idea. Its your program not mine. Ask that of whoever designed the program requirements.

>>BUT my problem is the GetMyMsgName() / GetMyMsgText() always return null or I don't know how to use them.

Most likely because those two variables have never been initialized to anything. Check the class constructor.

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

line 77: what will that do if the value of namelen is greater than 255, the max value that can be put in a single character ?

You need to translate that link into English because I have no idea what it says, don't even know what language it is.

>>The problem is I can't/don't know how to use the char * returned by the GetMyMsgName() method

What do you want to use it for?

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

My guess is that you have not even attempted to compile that code. It contains errors that you need to fix. For example:

CMyMessage line 77: error -- you can not store a pointer in one byte of memory.

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

you need both width and height so that your program knows how many lines of text to save. They can both be calculated when you know the upper-left and lower-right coordinates. It might be easier to just save the contents of the entire screen, write sub-menu, then restore the screen to erase the sub-menu. If you don't do anything with the color attributes than all you need is a buffer that's 24*80 = 1920 bytes. double that if you need the color attributes too.

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

Yes the reader should also lock with the mutex. I suppose you could have just one queue for all readers, as long as the objects in the queue have something to tell you what message goes to whom. Something like that is what MS-Windows does with the windows messages -- each message contains a handle to the destination window.

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

Yes I think its misplaced thinking. What if there are no items in the queue, and reader tries to read while writer tries to write? Everyone needs to be locked out while writer tries to write to the queue. Depending on how your code is written there could be more than one reader at the same time. But writer should have exclusive use of the queue data.

There are several ways to accomplish that. One way is setting up a mutex. Under MS-Windows another way is via CRITICAL_SECTION.

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

what's the value of es when that function is entered? The screen address is at 0xB800:0000, so you have to read starting from there. I think your function needs to set the value of es and not assume it already contains the correct segment value.

bx = upper left corner
ax = lower right corner
cx = width -- this is one problem. We need the height, not the width. The width can be calculated from bx and ax.

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

You can use some non-standard functions found in conio.h, assuming your compiler supports them.

time_t t1 = time(0);
time_t t2 = t1 + 60; // one minute timeout
while( !_kbhit() && t1 < t2)
{
   // do count-down timer
   Sleep(100); // delay 100 milliseconds
   t1 = time(0);
}

if( t2 >= t1)
{
   // timeout expired
}

// not do the cin stuf here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

A vector is an array of objects which handles most of the memory allocation and deallocation for you. There are several tutorials for vectors, just use google and you will easily find them.

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

I don't know how to initialize it, but try this and your solution doesn't work. My suggestion is not to put const variables inside structures. It wouldn't make any sense to put them inside a structure anyway because by definition you set a const variable to a single value which does not depend on any given instance of the structure. const variables have the same value for all instances of the structure and can never be legally changed. Of course you can typecast out the const and change it that way, but that's cheating.

struct mys
{
    char buf[255];
    const int value;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't need a switch statement for that.

objectclass* objects = new objectclass[numberfobjects];

or use a vector of objects

vector<objectclass> objects;
objects.resize(numberofobjects);

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

just include <list> header file. See this link

#include <list>

using std::list

int main()
{
    list<int> MyList;

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

Walt is correct, you are leaving those files open. That's won't happen if you would remove the parameters and declare the streams inside the functions that use them, as I suggested over 4 hours ago.

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

But I read 99.9 or 100 into the studentGPA array, it should've stopped iterating right? It just keeps giving me 0's. The first line is supposed to be the last name, then the GPA is supposed to be on the next line.

No because your logic is backwards, as I previously explained. Your program reads a value, increments the counter then expects to find the value that was just read in the previous slot of the array. You have to check for 99 before incrementing the counter, not after.

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

Thank ye' dragon of ancientness.. i think the main problem I ran into is forgetting to pass fstream objects by reference. aside from that, a few typos and I be good to go.

No, that is not all the problems. Read the rest of my post where I mentioned opening the files in two different places. You can't do that.

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

line 18 initializes all array elments to 0. Therefore, line 28 can never find one whose value is anything other than 0. When the loop is first entered, the value of counter is 0 and the value of studentGPA[0] is also 0. The next iteration of the loop the value of counter is 1, so the value of studentGPA[1] is 0.

I think the solution to your program is to use a do loop, not a while loop, so that the test is at the bottom of the loop instead of at the top.

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

line 92: isdigit is a macro that returns a bool value (true or false, 1 or 0) You can not compare it with a value as you have tried to do in that line.

Other errors I found are just careless errors, such as misspelled function names. Check the error messages better and you will be able to correct them.

ifstream and ofstream objects have to be passed by reference, not by value, like this line: void load(ifstream& infile); But that is also going to get you into deep trouble because the streams were already opened in main() and your program is trying to open them again in load() and save(). Do that is just one of the two places, but not both. Since the streams declared in main() are not used for anything just don't pass any parameters to load() and save(), and declare the stream objects in those functions.

Clinton Portis commented: muy bien +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, there is that potential problem, which is why I mentioned it in my post. But you will find many many threads which have contributions by several people. Its not just a two-sided two-people threads.