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

How to do it depends on the contents of file1. If file1 only contains one line of text then it should be pretty simple

ifstream file1("filename.txt");
ofstream file2("outfile.txt");
string input = "Hello World";
string line;
file1 >> line;
file2 << line << input;

It becomes a little more complex when the contents of file1 is more than one line. In that case you need to use a loop to read file1 and write to file2.

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

So for sure, I can go into Dev C++ (The Compiler I use), select new project >> console app (instead of windows app) >> then create a C++ app using the C++ Console lib, and the Winsock2 library?

Everyone has told you that about a million times now :)

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

Not directly, but there are a couple work-arounds.

1) use a series of if statements to test the string value then call the function

if( pie == "do_something" )
   do_something();
else if(pie == "something_else" )
   something_else();
// etc etc for all string values

2) use <map> to map string values to function pointers.

3) create a structure that is something like 1) above. Useful if there are lots of functions.

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

winsock IS part of win32 api. If you are looking for more complex client/server console code then you can find it by downloading the library here

>>No Windows API is different. Console applications are the DOS window.
You don't have to write a windows program to implement some win32 api functions.

Freaky_Chris commented: Thank god i'm not alone +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I like it, but can only play one key at a time because you have to use it like playing the piano with one finger. Now if there was a way to play it using all 10 fingers (and maybe toes too)!

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

Oh gee golly moses. This was the first in the list of google links

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

CodeProject has some articles that may help you.

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

google "bubble sort algorithm" and you will find lots of example code.

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

>>i want an instant answer
With a title like that most people will just ignore you.

And you have to be a lot more specific about what you need. There are billions of different answers to the crappy way you formatted your question or statement.

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

just a few templates you have probably already used
vector
string
fstream
ifstream
ofstream

Rashakil Fol commented: What the fuck are you talking about? -1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read what I posted -- everything ... carefully.

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

The print() method doesn't need a parameter at all.

This time read all the code and correct the spelling as I did.

Invoice.cpp

void Invoice::print() 
{											//print values in current bill
	cout<<"Invoice Number: "<<getInvoiceNum()<<endl<<endl;
	cout<<"Part Number: "<<getPartNum()<<endl;
	cout<<"Part Description: "<<getPartDesc()<<endl;
	cout<<"Quantity Shipped: "<<getQuantityShip()<<endl;
	cout<<"Unit Price ($/item): "<<getUnitPrice()<<endl;
	cout<<"Sales Tax Rate: "<<getSalesTaxRate()<<endl;
	cout<<"Sales Tax Amount: "<<calcSalesTaxAm()<<endl;
	cout<<"Shipping Cost: "<<getShipCost()<<endl;
	cout<<"Total Cost: "<<calcTotCost()<<endl;
}

invoice.h

void print();

main.cpp

if (bill[place].getInvoiceNum() == inum)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't create two threads about the same problem. I merged your two threads and don't intend to do it again!

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

>>'getShippingCost' is not a member of 'Invoice'

Yes -- you didn't see the code I posted earlier?

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

look at the parameter in the .h file -- it is a pointer. Now look at the parameter in the line you quoted -- that is NOT a pointer. They have to be consistent, one of the two has to be changed.

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

>> I'm not sure why but I keep having alot of problems.
What are the problems? Error messages? compiler you are using? Operating system ?

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

Several problems
1) add the const keyword

2) need to add () to function method calls

void Invoice::print(Invoice bill) const 
{											//print values in current bill
	cout<<"Invoice Number: "<<bill.getInvoiceNum()<<endl<<endl;
	cout<<"Part Number: "<<bill.getPartNum()<<endl;
	cout<<"Part Description: "<<bill.getPartDesc()<<endl;
	cout<<"Quantity Shipped: "<<bill.getQuantityShip()<<endl;
	cout<<"Unit Price ($/item): "<<bill.getUnitPrice()<<endl;
	cout<<"Sales Tax Rate: "<<bill.getSalesTaxRate()<<endl;
	cout<<"Sales Tax Amount: "<<bill.calcSalesTaxAm()<<endl;
	cout<<"Shipping Cost: "<<bill.getShipCost()<<endl;
	cout<<"Total Cost: "<<bill.calcTotCost()<<endl;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

. What can you do with Vista that I can't do with XP?

I just found out by accident that I can watch Blue-Ray formatted DVD movies on my Vista Home Premium computer without having to download and install any additional programs or plugins. M$ Media Player works like a charm :)

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

<snip> means I intentially omitted code, such as snip it with a pair of sizzers.

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

The problem is at the last line of invoice.h -- a semicolon is required at the end of a class declaration.

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

You are going to have to add more parameters to the bubble sort function. When the primary array members are exchanged, all the other array members must also be exchanged so that all the arrays are kept in sync with each other.

Example:

void bubbleSort(string Name[], int id[], float grade[], char letter[])
{
<snip>
 if (Name[index]> Name[index+1])                                {
{
       string temp=Name[index];
       Name[index]=Name[index+1];
       Name[index + 1] = temp; 

       int idtemp = id[index];
       id[index] = id[index+1];
       id[index+1] = idtemp;

        // now do the same think with the other arrays
}

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

Here are the data types in C -- the actual size of the data is not specified by the language because it may be different on each platform. You have to look in limits.h header file to find out the minimum and maximum values that any given data type can hold.

Here are the data types, and most common size for 32-bit C compilers on MS-Windows and *nix. I believe they are different for both 16-bit and 64-bit compilers.

ctype              size in bytes
char                     1
short                    2
int                        4
long                     4
float                     4
double                 8

A string is just an array of characters (char).

Each of the data types above can be either signed or unsigned, but the size is the same, only the minimum and maximum values change between signed and unsigned.

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

AFAIK there is no limit to the number of stars.

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

Neat -- but I never figured out what I was supposed to do.

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

Like I said before, do whats in the inner-most parentheses first, then work yourself out. Once you have removed all parentheses, work the statement from left to right.

For example: a - ((b * c) / d) + e; First calculate b*c, then divide that result by d, finally subtract that result from the value of a and add e.

f = b * c;
now the equation will look like this: a - (f / d) + e g = f / d; ===> a - g + e

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

No fix that I know. Try multiplying everything by 100 and use int math.

Freaky_Chris commented: thanks +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Don't give me a fish, teach me how to fish.

Just trying to answer your question. If you don't like the answer I gave you, then I'll shut up.

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

Its a difference in compilers and the way they handle floating point arithmetic. VC++ 2008 Express produces 0. Dev-C++ produces the value you quoted. Dev-C++ is an old compiler now and may have a few bugs. Maybe someone with CodeBlocks can try it to see if the bug has been fixed.

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

I can break the execution of the following code before the compiler starting to execute it or after execution of it.
But the line contains many steps, I simply want to trace it, How?

while((*(Pbuffer + i) = *(Pbuffer + j++)) != '\0')

First do whatever is inside the parentheses, then do the rest.

1) calculate the address Pbuffer+i -- increments pointer Pbuffer by the value of i, and store that value somewhere.

2) calcualte Pbuffer + j and saves that someplace else.

3) increment j

4) copy the character at the pointer calculated in 2) above to the address calculated by 1) above. If i and j had the same value then both 1) and 2) would result in the same address.

5) if the character at the address calculated in 2) above is '\0', then stop the loop.

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

Mr,Ancient Dragon
you said:
>>>>Next it asks if i points to a space, and if it does not then incremenet i.

how can you decide it, why not j?

if (*(Pbuffer + i) != ' ')
			i++;

Read the code! Does the code say j? NOOOOOO

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

We have no clue what you intend to put in those for statements, therefore no one can really answer your question. You could create a template, a function, or even a macro, all depends on what you want to do with it.

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

you are attempting to pass an array of strings to getSize(), but it only expects an array of characters. getSize() is nothing more or less than your own version of the standard C library function strlen().

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

you could put it in a function so that it can be called as many times as you like.

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

You use dll functions all the time in c++ programs. Every win32 api function and every standard c and c++ functions are contained in dlls. (they could also be statically linked, but that's for another discussion) So use your dll just like the others, include the header file and link with the *.lib that was produced with the dll.

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

m_Test is apparently a member of cls class. CreateInputFilter() is not a member of that class, so it doesn't know what m_Test is.

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

>>How can I monitor every little step of the function like that?

1) use a debugger

or
2) take a short test string and follow it manually. For example: "H W". Initially variables i and j are both 0, so it will just copy the character 'H' onto itself, then increment j so that j points to the space. Next it asks if i points to a space, and if it does not then incremenet i.

Second loop iteration: i and j are both 1 and both point to the space. So it will copy the space onto itself, then ask if i points to space. It does in this case, so it will NOT increment i.

Third loop iteration: i = 1 and j = 2 so it copies the 'W' onto the space. j is incremented to 3 and since the character at i is now a 'W' instead of a space the value of i is incremented to 2.
The string now looks like this: "HWW"

Fourth loop iteration: i = 2 and j = 3. The string's null terminator is copied to the second 'W' in the string so that the string is contains this: "HW". The whole thing stops because it just copied the '\0' character.

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

The first parameter to averageGrade() is supposed to be an int array, you are attempting to pass an array of Student classes. The second parameter is supposed to be the number of elements in the first parameter -- you are attemtping to pass a float that represents the average. The parameters in the actual function call must match the parameter list in the function prototype.

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

Did you read my previous post? Did you understand it? That code has the same identical problem as the first one you posted here.

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

Your version doesn't work because the first parameter Dest needs to be passed by pointer, not by value

#include <iostream>
#include <cstring>
using std::cin;
using std::cout;

void StrCpy(char ** Dest , char* Src )
{
 int i;
 char *tmp = new char[strlen(Src)+1];
 for(i = 0 ; *Src!='\0' ; Src++)
    tmp[i]=*Src;
 tmp[i]='\0'; 
 *Dest = tmp; 
 for(int i= 0 ; tmp[i]!='\0' ; i++)
   cout << tmp[i];
}

void main()
{  

char *string1 = 0;
char * string2 = "EL";


StrCpy( &string1, string2);
 // while(*string1)
 //   cout << *string1++; 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Probably far too long but it works.
Only because you were very lucky in your tests.

>>getline(RapidShit, ****Nipples);
What does that pointer Nipples point to? Nowhere -- just some random number because Nipples was never initialized.

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

My guess is that in main.cpp, the Graph object has not been initiaized, so when ReadGraph() is called and attempts to delete arrayEdges, CRASH/COREDUMP.

In main() initialize all Graph variables to 0 before calling ReadGraph() to see if that resolves your problem.

int main()
{
    Graph g;
    memset(&g, 0, sizeof(Graph));
    readGraph(g);
<snip>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string ****Nipples;
Forget about doing that! It won't work. That is not four strings, but a pointer to pointer to pointer to pointer of type string. Amazingly it compiles without error, but that doesn't mean it will work, which it won't.

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

I would first create a structure

struct words
{
    std::string word;
    int count;
};

Next an vector (array) of those structures

vector<words> wordArray;

Now, then the program reads a line, check wordArray if its already in the array. if it is then increment the count. If not, then add a new element to the vector. When done, you will have the information you need to display on the screen.

Another method is to use a <map>, but implementation is left for someone else.

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

Every line in a text file ends with '\n'. According to your instructions you would have to skip the last word of every line that is read. Lines do not have embedded '\n' characters.

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

>>string ****Nipples;

OMG what in hell are you trying to do here??? If you are trying to code an array of string's then its string Nipples[4]; But the reading part should look like this: (I hope you change the variable names before turning in the assignment because your teacher may not be that humerious.)

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
    ifstream RapidShit ("C:\\Rapid.txt");
    vector<string> Nipples; // an array of strings
    string line; // one line in the file

    if(RapidShit.is_open())
    {
        while (getline(RapidShit, line) )
        {
           Nipples.push_back(line); // add to the array
        }
        // now you have the entire file in memory.  Search each line
        // for the desired entry.
    }
    cin.get();
    return 0;
}
William Hemsworth commented: hehe x) +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Variable sums in the second code snippet is being used before it has been initialized. Look on line 5: what is the initial value of sums.x? Answer: its unitialized and could contain any random value. So the initial result of line 5 is undefined because we don't know the value of sums.x.

To correct the problem, you need to add one or more lines between line 2 and 3 that initializes all values in the sums variable:

sums.x = 0;
sums.y = 0;
// etc etc for each member of that structure
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

What about Buffer Overflow? :P

That is a problem with all standard C functions. If you use one of the new Microsoft compilers, Microsoft declared them depreciated and wants us to use the _s functions, such as strcpy_s(), which has an additional destination buffer size parameter. But even that could cause buffer overflow if the calling function passed the wrong buffer size. There is no 100% bullet-proof method in C to prevent buffer overflow. But if you follow the rules and bother to actually read the function's requirements then you can minimize the buffer overflow problem.

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

sum them all up and divide by the size of the array. For example

int a[3] = {2,4,6};

The sum is 2+4+6 = 12
The average is 12/3 = 4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't get it. How do you go from "40 20 ..." to "2 1 3 0" ?

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

can I just add, you need to remember to add a *dest=0; line after the while. You will need something similar in any of the other posts.

No with Arkm's algorithm you don't because it will also copy the null terminator.

StuXYZ commented: Your correct, I don't know why I hadn't noticed that! +1