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

Post the line of code that caused that error because I'm not a mind reader or clairvoyant.

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

test.txt is a binary file, not a text file so getline() doesn't know how to read it. Then you are putting all that binary stuff into a std::string and ucing cout to display it -- cout can't because it doesn't know how to display binary data when converted to char.

Use a hex editor on that test.txt file and it contains the 4 values that were written.

Maybe this is what you want?

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
int main()
{
	// fill up the vector with 4 integers
	vector <int> vec;
	vec.push_back(21);
	vec.push_back(23);
	vec.push_back(26);
	vec.push_back(29);
	cout << "Numbers in vector are:" << endl;
	for (size_t i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	//write out the vector contents as chars to a text file
	ofstream outfile("test.txt");
	if (outfile.fail()) {
		cout << "test.txt"
		<< endl;
		return 1;
	}
	for (size_t g = 0; g < vec.size(); g++) {
		outfile << char(vec[g]);
	}
	outfile.close();
    vec.erase(vec.begin(),vec.end());
	//now read the chars back in as the ints [21, 23, 26, 29]
    ifstream infile("test.txt", ios::binary);
	if (infile.fail()) {
		cout << "Error opening test.txt"
		<< endl;
		return 1;
	}
    char c;
    std::string str;
	while (infile.good()) {
        c = infile.get();
        std::stringstream sstm;
        sstm << c;
        str += sstm.str();
	}
    infile.close();
	cout << endl << "String read in is:" <<endl;
	for (size_t g=0; g<str.size(); g++) {
		cout << int(str[g]) << " ";
	}
	cout << endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read newspapers, see headhunters, ask friends/family

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

you need to use the win32 api communications functions

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

vc++ 2008 Express

Dev-C++

I know there are others. All C++ compilers also compile C code, so you don't need separate compilers for that.

For more information and helpful stuff see the Read Me threads at the top of the C++ board.

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

Are you doing command-line builds or building in the IDEs ? If command-line builds then you have to set up the environment for each compiler by running the vcvars32.bat file in the compiler's bin directory.

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

The input file is opened in text mode, which means your program will never see the '\n' character(s) because getline() will filter it out, leaving only the characters up to but not including '\n'.

That read loop is wrong anyway because eof() doesn't work that way.

while (getline(infile, tmp)) {
		str += tmp;
		str += "\n";
	}

I don't know what you mean by reading # 26. Does that file contain binary information? If yes, then it isn't a text file.

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

Compilers are free to choose to ignore the inline keyword or not.

Move the code in test2.cpp to test2.h since you use the linline keyword, then delete test2.cpp from the project.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
char ch;
 while ( cin.get ( ch ) && ch != '\n' )
{
    if( isalpha(ch) )
    {
         //do something
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Maybe you need to upgrade your GF to a newer model :)

Some girlfriends do not need upgrading... just proper maintenance. However; if you have chosen a model that is not compatible with you, or if you have chosen a model that is beyond your means to afford/perform the proper maintenance, then I suggest trading her in for one that is more right for you. Be careful though! Some makes/models have a self-destruct mechanism that automatically initiates when they sense you are interested in another model. If you are happy with the make/model that you have currently and are just looking to upgrade, then I suggest purchasing the Engagement/Marriage package. Again... be careful! Some makes/models are not compatible with this upgrade and lose some vital functions after installation. The functions that seem to be mostly affected are the Career, Sex and Reasonability functions.


FYI... This information could also pertain to those wishing to upgrade their current boyfriend models. Although the Marriage upgrade does not seem to create as many system errors in the Sex function after installation as much as it does in the some girlfriend models, the Career and Reasonability functions could still be adversely affected.

http://www.answerbag.com/q_view/381052

Alex Edwards commented: =P +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why are you using malloc() in a c++ program -- malloc() doesn't know how to allocate c++ objects? Use the new operator instead.

And you can not use the delete operator to free memory that was allocated by malloc(). delete only works with new.

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

If the user keys in more than just a single character you can flush the input keyboard buffer of all remaining keystrokes. See Narue's article here about how to do that.

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

Do the requirements just one at a time so that you don't get too confused and overwhelmed by the size of that assignment. Don't try to code it all at one time either -- code a few lines, compile, make corrections, compile again until no more errors. Then code a few more lines.

For example, do this part first:

You will do this using a single structure, so that string names and numeric point values may be housed in a single structure. As the items are used, they are removed from the inventory.

Then move on to the next requirement in the assignment.

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

C and C++ do not have "END IF" statements.

int score;
    char grade =0;

     // read in total score 

    cout << endl;
    cout << "Enter total score (float, must be <= 100): "; 
    cin >> score;  
     
    if (score >= 85); 
       grade = 'A';
    else if (score >= 75); 
        grade = 'B';
    else if (score >= 65); 
        grade = 'C';
     else if (score >= 55);
        grade = 'D';
     else 
        grade = 'F';

     // display the result 

    cout << endl; 
    cout << "Your grade for CMSC 101 is: " << grade << endl; 
    return (0); // terminate with success
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can't input and output to the file at the same time without some very fancy footwork by repositioning the file pointer to the beginning of the file before the write. The way I understand what you want, the file only contains one line of text, which you want to change each time you run the program. The simplest way to do that

open input file
read the line of text
close input file
open output file, with ios::truncate flag so that the current line is erased.
write new line of text to the file
close output file

Notice that it is not necessary to have both input and output files opened at the same time.

Hope this helps :)

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

AD's pseudo-code is exactly what I said.

Yup -- but apparently he didn't understand what you meant. For that matter, he may not understand my pseudo code either :)

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

I have no idea why it can't run -- are you trying to run it on the same operating system that you compiled it on -- such as compile on MS-Windows and attempt to run on *nix :) If you expect an answer you need to ask a more detailed question.

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

Thanks for all your help. I had to uninstall the 64-bit version of MySQL and install the 32-bit version because VC++ 2008 Express is not a 64-bit compiler. I suppose I could get a different compiler, but why ???

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

Like I said, its a simple function. You might want to enhance it to check if the keyword appears multiple times on the same line.

int grep(std::string& filename, std::string keyword)
{
    int counter = 0;
    std::string line;
    ifstream in(filename.c_str());
    if( in.is_open())
    {
          while( getline(in,line) )
          {
              if( line.find(keyword) )
                   counter++;
          }
    }
    return counter;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

post the line of code that gave you that error. If you want that function to allocate the memory for the pointers then the pointers will have to be passed by pointer, not by value void fbExeCode(int BldCnt, char** fbCodeAddr, char** tempAddr) -- note the two stars. You will have to make a number of other changes in that function, such as *fbCodeAddr= malloc(1024); . Also not that malloc() in C language does not require typecasting. If you put your code in a cpp file then it is being compiled as c++, not C.

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

If you know you want exactly 20 bytes from incoming data then your program should just wait until it gets all 20 bytes before proceeding. That means it will have to sit in a loop waiting for incoming data at the port. The input buffer should be just an unsigned char array rather than a structure.

For this to work you will have to compile with 0 packing.

#pragma pack(0)
void GetData(unsigned char* buffer)
{
top of loop
   read port
   add data to tail of buffer
   have we read 20 bytes yet
   No, then delay a bit and return to top of loop
   yes, exit loop
end of loop
}

int main()
{
    struct bitfields bf;
    GetData((unsigned char*)&bf);
}
Salem commented: Exactamundo! +23
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 32: you can't typecast ascii to unicode. should be something like this: LPCTSTR name= _TEXT("mydata.txt");

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

1) Are you going to tell us what your instructor wanted you to do, or do you expect us to read your mind ????

2) You need to make the test immediately after the line cin.ignore() to prevent the rest of the code incide that loop from executing.

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

Or you could just simply open the file in your program, read each line, search for the keyword then increment a counter when found. A pretty simple program to write if you already know file i/o functions. If you don't then this is a good opportunity to expand your knowledge of C++ standard classes.

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

For other than English characters you should compile c++ programs for UNICODE. Exactly how to do that is compiler dependent.

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

My guess is the input file isn't getting opened. Afte the open statement check to see that it was opened.

if( !Infile.is_open() )
{
   cout << "Open input file failed\n";
   return 1; // abort the program
}

use your compiler's debugger and step through the program one line at a time, that way you can see how the program is being executed and the value of all variables.

Also remove the else on line 37. You want both if statements to be executed because they are calculating both the largest and smallest value.

line 28: put "\n" at the end of the line so make the output file easier to read.

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

If anyone can answer my question on PFO I'd apprecaite an answer. I don't want to repeat it here because it is somewhat lengthy.

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

The return type of line 8 and 43 must be the same. The same with the other function. Change the return type of functions prototypes on line 8 and 9 to void and your problem will be solved.

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

>>The only thing I can figure is that it starts counting at 1 instead of 0 a
No, arrays are always numberd beginning with 0. The a+5 in line 9 that you posted is 1 element beyond the end of the array, which satisfies the end statement that you posted. So it will fill array element numbers 0, 1, 2, 3, and 4 but not 5.

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

The difference is how you want to view the array. Bla[64] is just a one, dimensional array that contains a simple list of items, for example you could have an array that contains a list of 64 varieties of fruits and vegies. The Bla[8][8] is an two dimensional array, such as one that you might see when you are using Microsoft Excel spreadsheet. It contains 8 rows and 8 columns. The rows could represent the names of students while the columns represent the names of fruits and vegs that they eat.

Another example of a two dimensional array is the rows represent student ID numbers and the columns represent the student grades of exams during the semester. You can extend this concept to a three dimensional array such as Bla[5][8][8], which is the examp test cores for 5 different classes.

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

you could do something like this, assuming you don't need to keep all the names in memory at the same time

int count = 0;
infil >> firstStudent;
while( infile >> lastStudent)
   count++;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) delete all those unreferenced variables. They just clutter up your code and compiler err/warning messages.


2) after completing 1) then you can see the real errors. One of them is that you used ( when you should have used { in the opening function brace. The other is that function quit is not declared correctly.

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

I would also ditch the MFC file handling classes such as CFile and CArchive, but use normal standard c++ fstreams and std::string, which are a whole lot easier to use. That assumes you are using a compiler that supports fstreams and std::string -- some embedded compilers do not.

Alex Edwards commented: Compilers that don't support fstream == fail! X_X +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those symbols are in different fonts, which require a GUI program such as M$ Word or your browser to display them. Can't use them in normal console programs.

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

You can find out what namespace it is by reading the header file in which it is declared or reading the programmer's documentation (for example looking it up in MSDN if it is a win32 api function).

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

resolved with the using clause, such as using namespace std; . Alternatively you can just put the namespace when you declare the object, such as std::string mystring; or mynamespace::myobj obj;

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

what makes you think managed code runs faster than unmanaged code? Faster is a relative word -- top speed is not an issue with programs that require human interaction.

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

Very briefly, clr is managed, .NET, program. Win32 console is not.

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

If you are a Veteran, you can go to a Veteran's Hospital.

:D To get into a va hospital the patient needs military-related physical injuries. And even then I would go there only as a last resort.

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

I didn't get the errors you got using VC++ 2008 Express. Probably one (or both) of two reasons

2) Read this short tutorial about how to set up the project's environment.

3) download and install the Windows Platform SDK from Microsoft site. It contains the openGL headers and libs.

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

Seek and thou shalt find.

>>How do we know the type the pointer points?
You have to declare the data type when the pointer is created. int* iPointer; >>Is it compiler specific?
No. Pointers are defined by C and C++ standards, so all compilers comply.

William Hemsworth commented: :) +4
Alex Edwards commented: Though I know it's not your style, it would've been funnier if you said "GIYF" =P +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) You will have to post the pragma from glaux.h that is cause the problem there.

2) warnning 4996: I always disable that because it isn't really a problem #pragma warning(disable: 4996) put that near the top of the *.cpp file

3) just ignore all those warnings you got after closing your program. Those are just normally and every program gets.

>>But the Error Form tell me that the "Initialization Failed"
Hard telling what cause that. Without seeing the code we are just shooting in the dark.

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

Nobody can help you if you don't post the code. Maybe your recursive function didn't know when to stop and cause stack overflow or something else just as bad. Check to see if there is something in the function that will make the recursion stop. Also make it stop after only a few recursions and see if the same error occurs.

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

If you only want something done on Saturday (when dow == 6) then write a bit of code that will call Sleep() and put your program asleep for 24 hours, then check again. Make sure the program waiks up again at midnight so that the next checks will work.

Once the day is 6 keep checking once a minute until the hour is 0 and minute is 14.

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

thank u...i'll surely make these changes...
if u dont mind i've few problems that i am unable to solve....if u dont mind i'll post them,so that u can help me sort them out

Just don't expect us to write the code for you -- we will gladly help YOU do that though :)

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

Did you link your application program with the *.lib file that the compiler produced for the *.dll program?

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

1) gets() -- never use it. Read this for explaination of why.

lines 26-27: There is no need for variable x. Just use the parameter variable n.

line 41: >>void putdata(int n); Delete that line because its not necessary to prototype a function before actually writing the code for it. Most programmers will have all function progotypes at the very beginnning of the program, after the #include <blabla> statements.

line 44: same as previous comment about 26-27.

No comments about the rest of your program because I don't use ancient Turbo C++.

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

First write a program that compiles another program, probably by calling make.exe, nmake.exe, or some other such program that does command-line compiles on your computer. That will be the easiest part because all your program is doing is apawning another program.

The more dificult part will be running the test cases. Write the tests in an ordinary text file using notepad or some other editor that your program will read. Spawn the test program (the one your program just compiled) and stuff its keyboard buffer with the test information just like someone had typed it. That will be the somewhat challenging part, depending on what operating system the two programs run under. Then of course your program will have to learn how to detect what the test program did with the information.

My guestimate is that it will take you a year or so to write a useful program like that which can be marketed.

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

you don't specifically allocate memory for the string object because it is not a pointer inside the structure. Just allocate tmp and everything will be allocated ok tmp = new edge;

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

40% Republican and 36% Democrat. So I guess that means I'm 24% Libertarian.