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

Do it however you want, but you still won't be able to maintain the spacing and tabs of the original program that way because the >> operator skips over them.

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

how did you do it in QBasic? did you keep the script? If you did maybe you can just port it to C.

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

Reading the entire file into memory then rewriting it will work on small files. But doesn't work very well on huge files because of the large amount of memory it will take up and the amount of time it takes to load those vectors. How will that program work on a multi-megabite file ?

>>Right, but I want to keep the spaces and everything else. Is there any way to do that?
And your last post doesn't do that either.

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

Calling database/ODBC functions to get or update data for the browsers is a pain in C or C++. But it can be done.

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

>>I'm confused
No supprised, because you can't write directly to the same file. What makes you think your instructions tell you to output to the same input file?

What is possible is output to a different file. Then when done, close both files, delete the original input file, then rename the output file to the filename of the original input file.

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

>>long int r = random(srandom ( (unsigned) x));int x = 27;
No No NO. You can not do that. The intent of srandom() is just like the standard C library function srand(), which is to be called only once during the lifetime of the program. After that random() can be called as often as you like to generate random numbers

// generate 10 random numbers
srandom( time(0) );
for(int i = 0; i < 10; i++)
   cout << random() << "\n";
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This is nothing more than a stupid rehash of another thread that was already answered. No point in doing it again. Just read the previous thread to get the answer.

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

>>if it is possible to ensure that my hook is always highest

No.

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

look at boost libraries and see if it has something useful in its math libraries. Or maybe mathlib has what you want.

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

Point is not a POD (plain old data) type so you must either create overload << operator for it too or print each part separately

struct Point
{
  int x, y;
};

...
ostream & operator << (ostream &output, Edge &e)
{

    Point p1, p2;
    p1 = e.getP1();
    p2 = e.getP2();
   output << p1.x << " " << p1.y << " " << p2.x << " " << p2.y;
   return output;
}

or

struct Point
{
  int x, y;

};
ostream & operator << (ostream &output, Point &p)
{
   output << p.x << " " << p.y;
  return output;
}

...
ostream & operator << (ostream &output, Edge &e)
{

   output << e.getP1() << " " << e.getP2();
   return output;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move srand() above outside that loop. It should be executed only once during the lifetime of the program. And the parameter should be time(0) so that it is different every time you run the program. Like this: srand( time(0) ); . Some compilers might want you to typecase 0 to unsigned int or size_t.

>>r = random();
Wrong. should be r = rand();

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

this works

void editFile(ifstream& infile, ofstream& outfile)
{
int countAlpha = 0;
int countSpace = 0;
char ch;

while( infile.get(ch) ) 
{
    //Change dashes to spaces.
    if (ch == '-')
    {
        outfile << ' ';
        countSpace = countSpace + 1;
    }
    //Change all characters to lowercase.
    else if(isalpha(ch))
    {
        ch = tolower(ch);
        outfile << ch;
        countAlpha = countAlpha + 1;
    }
    //Change digits to * (asterisks)
    else if (isdigit(ch))
    {
        outfile << '*';
    }
    else
        outfile << ch;
    }
cout <<"The amount of spaces written to the output file is "<<countSpace<<endl;
cout <<"The amount of alphabetic characters written to the output file is "<<countAlpha<<endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

instead of reading one line at a time, read one character at a time. when a white-space character is read that's the end of a word. Process the word, write to the file as previously shown, then just read/write each charcter until the next non-white-space character is read, something like this I suppose. I didn't compile or test it, but will probably work.

char ch;
string word;
while( infile.get(ch) )
{
   if( !isspace(ch) )
        word += ch;
   else
   {
          // end of word, so process it and write it to file
          outfile << word;
          word = "";
         while( infile.get(ch)  && isspace(ch) )
             outfile << ch;
         word = ch;  // save 1st letter of the word
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to write the words to another file, not the same input file, similar to below. The code below doesn't change anything but just writes whatever was read to the output file.

ifstream in("infile.txt");
ofstream out("outfile.txt");
while( getline(in, line)
{
     stringstream stream(line);
     while( stream >> word)
     {
            // convert the word if needed is not shown here
            out << word << " ";
     }
     out << "\n";
}

The above will replace all spaces and tabs between words with a single space. So

how                     now

will wind up as

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

1) I presume busy wait you mean the program displays something like the hourglass you see in browsers where the program continues to do something. The only purpose of the hourglass is to let the user know that the program is doing something that may take some time to complete. The block wait is like the message "Press any key to continue", where the program is actually stopped until you press a key to make it continue. When to use which one all depends on the program and what you the programmer want it to do.

2: >>Are there situations where the execution context of the process may have to be saved
MS-DOS 6.X and older is considerded a "uniprogramming system". The answer is yes because it too has hardware and software interrupts which, as its name implies, interrupts the execution of the main program for a little while to do something else, then when done the interrupt handler will return resume the main program where it left off. This is not a scheduled task switch as it is in multi-programming enviroments such as *nix and MS-Windows.

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

You have lost the line terminators '\n' because at line 41 it is reading one word at a time. You will have to rethink the logic of that program so that it can still see end-of-line '\n'.

I think the easiest way to do it is to read the input file one line at a time, use stringstream to split it into words, check the word to see if it needs to be converted to asterisks, then finally write the word to the output file. You don't need to use vector at all in this process, nor do you need to write additional functions.

string line;
string word;
open both input and output files
while( getline( infile, line )
{
    stringstream stream( line );
    while( stream >> word )
    {
         // convert just this one word before
         Search words.txt to see if word needs to be changed
               change the word to asterisks
         write the word to output file
    }
    write '\n' to the output file
}
close input and output files
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I suppose you replace line 56 with this:

string& word = message[k];
// now the rest of that alrorithm
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you declared outputLegend as const array but trying to pass it to a function that expects non-const. Change the function to require const

void printTxtArray(const char *B[]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

use a loop

string word = "Hello";
for(int i = 1; i < word.length(); i++)
   word[i] = '*';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 42: that's not the right way to write that loop. eof() doesn't work like that.

while( infile.get(ch) )
{

}

line 50: all that is going to output is the boolian value 0 for false or 1 for true. And that is why your output file is incorrect. Change the == boolean operator to = assignment operator.

line 67: delete that line.

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

why did you change main() ? All you had to do was write the increment() functions.

Just delete the crap you wrote and start again. This time only change line 6 where it says to

put increment function here?

. DO NOTHING MORE other than correct lines 1 and 2 to include the header file names.

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

It would be nice if you explained what this program is supposed to do. Given the input file what is the output file supposed to look like ?

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

>>what do i do next
Start by testing the word to see if it begins with a vowel. You will probably want to write a series of if -- else if --- else if --- statements to test each of the requirements.

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

Welcome to DaniWeb. Your use of the milspelled word enuf got me to searching the internet to see if it was really a correct spelling. Came across this article from about four years ago

Carrying signs reading "I'm thru with through," "Spelling shuud be lojical," and "Spell different difrent," the protesters — who first protested two years ago, but skipped last year — drew chuckles from bee contestants

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

did you try this: sprintf(buff, "%ld", lval);

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

vc++ 2008 has an excellent debugger -- you don't need dbg for anything. just learn to use the debugger that's build into the vc++ IDE.

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

>>Can anyone help with it
Not really. Your are probably using the wrong compiler and/or operating system. Just comment out that line and see what errors you get. You might have to define some stuff yourself.

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

You can use std::sort() algorithm and write your own comparison function for it. Here is an example And you can find more information in these google links

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

Oh i know,..i dont put the code below..thats why i dont get the output that I want? Actually what is cin.get();?

THANK YOU ancient dragon !

cin.get();

see fstream reference

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

The structure should contain character arrays, not pointers. It also needs more fields as required in the instructions you were given.

struct StudentName 

{
	char first[31];
	char last[31];
};
  • All work must be your own. You may discuss the material with other students but each student should do his/her own work.

That means we are not allowed to write the program for you. What you submit must be your work, not ours.

lines 23, 28 and 33: the Get functions should not have parameters. They should return const char*. For example

const char* GetFirstName() 
{

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

Nope, not me. What compiler and operating system. Its possible the lib you are attempting to use is 1) compiled by a different compiler, or 2) written for a different operating system, or 3) corrupt.

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

I don't get that output. Here is the full code of what I used to test

#include <iostream>  // std::cout
#include <fstream>
#include <iomanip>
#include <string>    // std::string
#include <vector>    // std::vector<>
#include <algorithm> //std::for each()
using namespace std;
// import "std" namespace into global namespace


struct exam {
	string examid;
	vector <int> total;
};
//int myfile;
int main() {
	ifstream stream1("..\\STA83SOL.txt");
	if ( !stream1.is_open()) {
		cout << "While opening a file an error is encountered" << endl;
	} else {
		cout << "Fail Di buka....." << endl;
	}
	vector <exam> exams;
	exam aExam;
    string tempExamID;
    int tempTotal;
    stream1 >> tempExamID >> tempTotal;
    aExam.examid = tempExamID;
    aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
    while (stream1 >> tempExamID >> tempTotal)
    {
        if(tempExamID != aExam.examid)
        {
            exams.push_back(aExam); // no more exam codes for this student.  Add aStudent to students vector
            aExam.total.clear();
            aExam.examid = tempExamID;
        }
        aExam.total.push_back(tempTotal); // add this exam code to current student's vector of exam codes
    }
    exams.push_back(aExam); // no more exam codes for this student.  Add aStudent to students vector
    stream1.close(); // We have read the entire file, so time to close it.
	{
		ofstream myfile;
		myfile.open("400.txt");
		if (myfile.is_open()) {
			myfile<<"+---------------------------------------------------+\n";
			myfile
					<<"|                       Conflict Graph              |                                    |\n";
			myfile<<"+---------------------------------------------------+\n";
			for (size_t i = 0; i < exams.size(); i++) {
				myfile<<"\n"<<i+1<<":"; // output student id

				for (size_t j = 0; j<exams.at(i).total.size(); j++) {
					myfile<<" "<< exams.at (i).total.at(j)<<"\t"; // output list of exam codes for this student
				}
				myfile<<"\n\n";

			}
		}
	}
    cin.get();
	return 0; …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> 'vector' : undeclared identifier
Don't you think that should tell you something about your program? Did you look to see where vector is declared?

Just in case you really have no clue you have to include <vector> header file.

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

copy it to a temp array then copy however you want

unsigned char tmp[sizeof(int)];
int x = 123;
memcpy(tmp,&x, sizeof(int));
// now you can copy tmp array the way you want to
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what version of MS-Windows are you using ?

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

Here's how to do it. As I said its only one simple line of code

Convert Fahrenheit to Celsius
Here's How:
1.Determine the temperature in Fahrenheit
2.Using your calculator, subtract 32
3.Multiply the result times 5
4.Divide that answer by 9
5.Your final answer is the temperature in Celsius

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

There are no functions -- you have to write your own. you might check out mathlib and boost, I don't know if they have a function or not. But its just a simple one-liner.

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

Stop creating so many threads about the same topic.

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

some more examples for MS-Windows and *nix

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

How do you <snipped link> with pencil & paper ? If you know that then doing it in C or C++ is trivel.

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

You would save yourself a lot of trouble by learning to use google. which found that link in just a few seconds.

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

line 15: delete it because its not needed.

Your logic in that while statement beginning on lines 26 to 50 is all screwed up. Here's the correction which is a lot less code than what you have.

int tempTotal;
    stream1 >> tempExamID >> tempTotal;
    aExam.examid = tempExamID;
    aExam.total.push_back(tempTotal);
    while (stream1 >> tempExamID >> tempTotal)
    {
        if(tempExamID != aExam.examid)
        {
            exams.push_back(aExam);
            aExam.total.clear();
            aExam.examid = tempExamID;
        }
        aExam.total.push_back(tempTotal); 
    }
    exams.push_back(aExam);
    stream1.close(); // We have read the entire file, so time to close it.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That second one from 1970 was right on target. The speaker was exactly right about how the computer would change our buying habbits.

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

Ok , sir !!!

What is the deal over here ?
can't a man make a joke ?
12 smilies is not that much ..!!!

sorry guys but u have to lighten up a lil

i hope someone can close the subject cuz it's not funny any more !

Sure we can -- like the infraction I just gave you for posting so many smilies -- I don't take kindly to people who laugh so much :)

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

>>it seems like the computer is switvching between tasks. Am I right?
Yes. Unless you have a duel processing computer then the os can only do one thing at the same exact time. It is just an illusion that it looks like two or more things run at the same time. The operating system contains a task switcher that gives only a small amount of CPU time to each program at a time. It has an array of threads that have to be serviced and switches the CPU between them in round-robin fashion. So when you call CreateThread you just add another thread to that list in the task scheduler.

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

line 3: wrong function parameters. There are only two valid ways to code that function: int main(int argc, char* argv[]) int main() You will have to change all the lines that reference sc to use argv[1] instead. Or you could just add another variable and leave the rest of the code alone. const char* sc = argv[1]; line 6: delete it like Aia askied you to do.

line 12: change it like below because you are destroying the file pointer and remove the semicolon at the end of that line. while(fgets( buffer, sizeof buffer, myfileptr) != NULL)

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

five in one just one day? thats a lot

No not really. You'd be supprised at the number of spammers we get sometimes. But its not as bad as it was a year or so ago.

I get a kick out of banning people :cool: I'd give anything to see their eyes when they are online posting their dribble and a mod bans them on the spot. ;) I've caught a few like that.

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

I tried to read some of those links -- horrible, someone needs to get off drugs. And the text fading in and out like that is extremly annoying. I'd delete this whole thread only because those links are soooo awful.

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

Yes I see that doesn't work. Try this

if( cin.peek() != '\n')
    {
        cout << "Error\n";
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

when you enter a non-digit cin will set the error flag so all you have to do is test for it

if( cin.error() )
{
   cout << "ERROR ...";
   cin.clear(); // clear the error flag
}