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

better off replacing that fprintf() with c++ fstream class so that the compiler won't complain so much.

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

If you use string, then use find() to locate the space, and substr() to extract the characters from position 0 to the location returned by find().

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

delete line 56 -- it does nothing.

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

Why did you use fgets() instead of fscanf()? fgets() gets the entire line without regard to spaces, which is not what you want. Look at the simple code I posted, it does what you need. All you have to do in that loop is add the word to the linked list or increment the word's counter if its already in the list. There is no need for that is_separator function because fscanf() will take care of that for you.

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

Its a lot easier to sort them if you use an array of 3 integers instead of 3 individual variables.

int arry[3] = {0};
for(int i = 0; i < 3; i++)
{
   cout << "Enter an integer\n";
   cin >> arry[i];
}
// now you can easily sort the array using one of the 
// many sorting algorithms.  The bubble sort is the easiest
// to code.  Google for it and you will find it.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You now have all the pieces you need, all you need to do now is put them together. In your original program, just delete lines 19-45 because they are not necessary. Then just write a simple for loop that displays the values of students and grades arrays, like the code Clinton already gave you.

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

@twomers

"The #include thing only works on compile time. Not run time" - so you mean the binary will have all the contents of the the included file???

Yes. Its not really all that big a deal since the program has reserved space for the data anyway. Even though you have the arrays declared in if statements the compiler will allocate memory for all of them at the same time somewhere in global memory (since they are declared static). The if statements just limit the scope of those arrays.

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

Is a core file produced? Yes, then use dbg on that core file and it will tell you where the crash occurred.

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

When I hit the Edit button to edit a post there is another active Edit button. Can you remove that button because its confusing.

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

>>The program is supposed to take in a file provided through standard input
That means get the name of the file from standard input, not the lines of the file. You have to open the file and read each word, something like this:

int main(int argc, char* argv[])
{
   FILE* fp = fopen( argv[1], "r"); // open the text file
   char buf[255];
   while( fscanf(fp,"%s",buf) > 0) // get a word
   {
    // populate the linked list with this word
   }
}
fclose(fp);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Modern 32-bit compilers to not support that header file because it was intended for 16-bit MS-DOS 6.X and earlier operating systems. The alternative is to use win32 api functions OpenFile() to open a comm port, ReadFile() and WriteFile() to read/write to it. MSDN has a large article about serial communications.

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

@gerard4143 :
@Dave : The first example is working, the structure gets populated with values in the inc file.

Yes it does work.

Ok, if its not possible then is there any other way to populate this structure using the inc files without using #include?

Read the file into the array just like it was any other normal text file.

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

>>Is there anyway to achieve this?
No because the #inc lude directive is processed at compile time, not runtime.

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

Hummm -- asking us to do your homework???

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

First you need a 2d array to hold the final strings. Then a row counter, a column counter, and a comma counter. In a for loop copy each character in the original array into the current row/column of the 2d array. When the 3d comma is found, increment the row counter to start a new row in the 2d array, zero out the column counter, and zero out the comma counter.

char string_array[20][80] = {0};
    char seed_array[] = "a1,b2,c3,a2,b1,c2,a3,b2,c4,";
    printf ("seed real=> %s\n",seed_array);
    char *p=NULL;
    int i,j,k;
    int comma_count = 0;

    for(i = 0, j = 0,k = 0; seed_array[i] != '\0'; ++i)
    {
        string_array[j][k++] = seed_array[i];
        if( seed_array[i] == ',' )
        {
            ++comma_count;
            if(comma_count == 3)
            {
                ++j;
                k = 0;
                comma_count = 0;
            }
        }
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. You can build windows gui programs, but you have to do it manually or buy someone else's program that produces windows resource files. You could also use a different IDE/compiler, such as QT which contains gui guilder.

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

Why did you make grades a double instead of an integer? doubles are not necessary in your program because nobody will have a grade of something like 75.123 (at least I never heard of such a thing).

First thing is to make a function that takes two arrays as arguments

void foo( int grades[], string students[] )
{

}

Notice in the above you don't know how many elements are in each of the two arrays. One way to fix that is to pass it as another parameter

void foo( int grades[], string students[] , const int size)
{

}

In the above function just create a simple for loop and display the information for each of the elements of the arrays.


in main() all you have to do is call that function

int main()
{
...
...
    foo( grades, students, size );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Also, I have tried the tolower() function but the compiler will not accept it. Here is how I tried to code it:

flavor = tolower(flavor)

What did I miss?

tolower() only works on a single character, not the entire string.

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

line 21: >> getline (cin, flavor) >> flavor;
Remove the ">> flavor" at the end of that line.

You can not do switch statements on strings! switch only accepts integers. You will have to replace that switch statement with a series of if statements. Another way to do it is to change that menu so that you enter a number instead of a string

cout << "Welcome to Frozen Tongue Ice Cream Shop\n"<<endl;
	cout << "Please enter the flavor number of icecream sold or 'STOP' to exit.\n"<<endl;
	cout << "1.  Flavors avaliable:\n";
	cout << "2.  chocolate\n";
	cout << "3.  valnilla\n";
	cout << "4.  strawberry\n";
	cout << "5.  mint\n";
	cout << "6.  rocky road\n";
	cout << "7.  mocha\n";

Also note that you do not need both "\n" and endl because endl also causes '\n' -- leave it if you want your menu displayed with a blank line between menu items..

With the above menu you can enter a number instead of a string. Then change the data type of flavor to int.

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

what don't you understand -- you should start your own thread to ask a question.

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

>> int numbers[ARRAY_SIZE]; {10,20,30,40,50,60,70,80,90,100}

That is incorrect. Here is what you want int numbers[ARRAY_SIZE] = {10,20,30,40,50,60,70,80,90,100}; The index number is nothing more than the loop counter. Therefore you can delete the line for( index=0;index<20;index++) then cout the value of count instead of index.

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

Can not be done because MFC will not give you what much control over it. All the text in the edit control is displayed in the same color.

You can't use html in any mfc control.

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

line 9: string stop, flavor, count = 0

count is a string, so why are you setting it to 0 like it is an integer? I suspect you want this: int count = 0; line 26: >> if (flavor = 'STOP' || 'stop')
strings have to be enlosed in double quotes "STOP". Also the if statement is constructed wrong. You want this: if( flagor == "STOP" || flagor == "stop") Further reading that program shows that most of those other variables also need to be integers -- they are supposed to contain a count of how many scoops of that flavor were ordered. You don't do counts with strings.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")

You can delete those two lines because including windows.h forces those two libraries.

[edit]Oops! I was fighting the gargoyle and the program sometimes seems to hang as if it is an infinite loop.

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

I use Norton -- yes I know its not free, but I want to keep their programmers employed :)

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

What does setName() do?

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

>>it does not work!
What does that mean??? Are you getting compile errors? Yes, then post the errors and the code that caused the errors.

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

...
I did find some solution - a product called Zinstall XP7 that simply embeds the entire old XP into the new Windows 7 (I guess some VM is here to do that). Then you use both new Windows 7 and old Windows XP at the same time.
Sounds to good to be true...

While you're at it why not find a way to embed Ubuntu in Window7 too? Then you could have the best of all operating systems at the same time.

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

Its not working because thread functions must be either static alss members or functions outside any class. Address of a non-static class method can not be passed to any win32 api function. Make StartThread() static and the compiler will probably take it.

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

google for "ODBC tutorials". You will be expected to already have a good grasp on C/C++ language. There are other ways to do it, but ODBC is the most common.

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

You are asking about some pretty complex code, which I am not prepared to provide to you. Its been 15-20 years since I did worked with that. Your best bet would be to study some of these google links. At least one of them has some c source code, for what its worth.

Aia commented: Clarity is always a good answer. +7
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

In that case go back to the code you originally posted here. inportb() only takes one parameter. It returns the byte read.

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

julian dates is just a count of the number of days from 1 January to the current day of year. And that's all toJulian() is doing.

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

Does it use memory models, such as small, medium, compact and large? If yes, then it is a 16-bit compiler.

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

Do you want a preemptive task scheduler, or non-preemptive? In either case you will need to set up stack segments for each of the tasks, then in the task-switcher function save the value of all registers onto the current stack, switch stacks, the restore all register values for the new task. AFAIK you can't do that in C language -- use assembly code.

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

>>Can we do this using winsock hooks.
Probably not. You can hook into a browser itself, but not web pages. I suppose you could find out where a browser gets the web page from the internet and then rewrite the page.

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

That seed_array is declared wrong -- you need a 2d array of characters. such as char seed_array[20][200]; Instead of using strchr() it might be easier to use brute-force method

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

Here is one example of how to do it. I hope you are familiar with assembly language.

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

Yes, the 0x03f8 is the com port address for MS-DOS 6.X operating system. If you read through the links I posted you will find examples how to open the com port.

Are you using the 16-bit version of TurboC++ or the newer 32-bit version ? You can not use win32 api functions from the old 16-bit version of that compiler. My recommendation is to ditch that compiler and get a new one, such as Code::Blocks or VC++ 2008 Express, both are free.

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

I missunderstood, I thought C++ used the default(empty) constructor if its not implemented.

Only if you do not declare a constructor in the class.

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

you never implemented the class constructor.

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

The problem is that you are leaving the '\n' in the input buffer before calling getline(). call ignore() just before getline()

if(savedGame.is_open())
		{
			savedGame >> stamina;
			savedGame >> health;
			savedGame >> mana;
			savedGame >> level;
			savedGame >> strength;
			savedGame >> constitution;
			savedGame >> dexterity;
			savedGame >> newGame;
            savedGame.ignore(1000,'\n');
			getline(savedGame, weaponName);
			savedGame >> attack;
			savedGame >> strReq;
			savedGame >> dexReq;
            savedGame.ignore(1000,'\n');
			getline(savedGame, armorName);
			savedGame >> defense;
			savedGame >> strReq2;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

More info about pointers (link here)-- from DaWei on PFO.

kvprajapati commented: Cool! +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Its possible that GetOpenFileName() is sucking up your message. Call RegisterWindowMessage() to obtain a unique message for inter-application/thread communication. I don't know if that will resolve your problem, but worth a try.

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

I don ot think erase() would do the trick.. why not use strtok()?

Bad idea. strtok() will crash the program you posted because it will attempt to change the string literal.

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

>> How to compare file creation date and current system date

I would probably first call GetSystemTimeAsFileTime() to get the current system time into a FILETIME structure. Then just compare the two FILETIME structs.

It is not recommended that you add and subtract values from the FILETIME structure to obtain relative times. Instead, you should copy the low- and high-order parts of the file time to a ULARGE_INTEGER structure, perform 64-bit arithmetic on the QuadPart member, and copy the LowPart and HighPart members into the FILETIME structure.

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

you want to use the substr() method, not erase(). And delete line 8 because length isn't needed (unless you want to use it somewhere else).

string type = temp.substr(0, pos);
string value = temp.substr(pos+1);
AdRock commented: Exactly what i needed +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

C/C++ use "libraries", and "dll"s (MS-Windows) not packages. How to create one depends on the compiler you are using. Normally the source code for a library is all in one folder, and it doesn't matter what the folder name is as long as your compiler knows.

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

you can not use inport and outpout with any 32-bit or 64-bit compiler. Those functions are no longer supported by the operating system. On MS-Windows you will have to use win32 api functions, starting with OpenFile() to open the com port, ReadFile() to read from it, and WriteFile() to write to it. Here is a complete list of communications functions.