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

Make it a pointer instead of a reference.

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

The assignment is due Tuesday Nov 8! I hate to inform you but Nov 8 is tomarrow, Thursday. In any event, you are just now starting that assignment ???

Do the program one small step at a time, and compile frequently so that you don't get overwhelmed with errors.

First step is to design the file format. From the looks of that structure each record needs to have the phone, address and name. Since address and/or name can contain spaces I'd suggest surrounding them in the file with quotes or separating them with a comma. The '\n' will be used to separate records.

Next you will need two functions -- one to read a line and save the contents in the structure, probably mygetline() can do that. The other function is to write out the data to the file.

When you get that done, post your results and we'll help with the rest, if you need it. But unfortunately for you I doubt you can complete this assignment by 9:00 am tomarrow morning, which is only 15 hours away in my time zone.

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

and u must be polite with ur guests !!!!!

Absolutely agree. And most of the time we are.

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

>>but the problem is that same result is printed for any number
The scanf() line needs a pointer to n.

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

I DIDNT ASK FOR UR OPINION !!!!!!!

You're going to get it sometimes whether you like it or not. So get over it. We're all one big happy family here and do not like people with a lousy or smart-mouthed attitude. You are most welcomed to join in if you drop your greater-than-thou attitude.

I wasn't trying to be rude -- just asking you not to use abbreviations like that here because most people won't know what they are.

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

For a beginner, yes it was a waste.

>> "waw" in arabic means " what u did was"
Not many of us (probably nobody) speaks arabic here, which is a very good reason not to post such things.

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

Plonk

>>waw man ur a great guy
Oh! Narue when did you have a sex change :)

And what is waw

WAW or Waw can mean:

Watch and wait
the letter Waw in the Hebrew, Arabic and other (mostly Semitic) alphabets
IATA code for Warsaw Frederic Chopin Airport
WAW (Australian television station), a satellite broadcast TV station for Western Australia
an alternate transliteration of Wau, Sudan
World Association of Wrestling a British professional wrestling promotion
World at War
Write after write data hazard
WAW Velomobile
Wired All Wrong
WAW is also the callsign for Golden West Network.
WAW is also the abbreviation for the law firm of Wharton Aldhizer and Weaver located in Harrisonburg, Virginia or on the web at http://www.WAWLAW.com.

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

while compiling it shows this type of error

"Nonportable pointer conversion"

You're right -- I didn't read it hard enough. Should use single quotes, not double quotes, like this: for(code = 'A';code <= 'Z'; code += 1)

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

Quite simple -- first make sure you compile your program for DEBUG. Then use the functions in the Debug menu. You will use Start Debugging (F5), Step Into (F11) and Step Over (F12) the most. You can save some time by setting breakpoints so that the debugger will stop on the line you set.

It make take a bit to learn the debugger but after that find problems in the code becomes fairly easy.

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

what is the output of your program? The code looks ok, except I'd make code an int instead of char but that shouldn't cause any problem.

The format string needs a '\n' for line feed ("%c, %d\n",

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

Without knowing the values of the variables its quite impossible to determine the solution to your problem. What compiler and os are you using? You need to learn how to use your compiler's debugger so that you can single-step through the program execution and see that the variable's values are.

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

CFile is often used with CArchive to serialize MFC classes and objects. Otherwise its not a very good class for normal text file i/o.

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

you can make CAnimate a pointer

class CPlanet
{
 ...
   CAnimate* m_animateptr;
};

int main()
{
    CPlanet planet;
    planet->m_animateptr = new CAnimate;
}

But you should probably put the code in CPlanet to make it allocate all necessary memory for itself

class CPlanet
{
public:
    CPlanet(bool bNeedAnimate = true)
    {
        if( bNeedAnimate)
            m_animateptr = new CAnimate;
        else
            m_animateptr = NULL;
    }
 ...
   CAnimate* m_animateptr;
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You mean remove it from CPlanet? or leave it there and instantiate another instance of it in main(). I assume the purpose of CAnimation is to make the class rotate on its axis, so removing it from CPlanet would not be a very good idea. If you instantiated an instance of CAnimation directly in main() what would it do? What is it supposed to animate ?

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

>>Those were the good old times!
I disagree because those "good old times" had more disease than we have today, AIDS was 100% fatal, less fuel-efficient automobiles, so-called educational films taught children to hide under their desks in case of nuclear attack, and many many more disadvantages.

"Good old days" ??? There has never been a better time for most people than today (politics excepted)

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

>>Actually it works
Yes it will work if you do not define UNICODE because TCHAR is defined as char and sizeof(char) is always 1. So your code reduces to srf_ReadFile.GetLength()/1, or just simply srf_ReadFile.GetLength(). Now define UNICODE and your formula will change to srf_ReadFile.GetLength()/2, which will result in 1/2 of the actual file size if you are on MS-Windows or 1/4th the file size on *nix because sizeof(TCHAR) = 2 (a short int) on MS-Windows and sizeof(TCHAR) is 4 on *nix (a long int)

>>Few reasons I have to use it. First thing is I want to design GUI
Not a reason to use CFile. Just because you have an MFC program is not a reason to use CFile either. You can mix CFile with fstreams in the same program -- I have done it hundreds of times.

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

even the fstream example you posted is not workable.

line 4 does not calculate the size of a file but the number of TCHARs in the file, which might or might not be the same as the size depending on the UNICODE setting.

As for CFile, the answer is NO -- and that's one reason why I hate that class. Unless the file contains serialized MFC objects you are better off using normal c++ fstreams, assuming your compiler supports it (some do not).

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

>> Reputation-Altering Power
What is that? both you and I (and probably everybody else too) its value is 0.

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

you need to use the && operator, not ||

while (choice != 'Q' && choice != 'q');
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First, the program you posted is a bastardization of C and C++ languages. As for your problem you need to flush the '\n' (Enter key) from the keyboard buffer after the sscanf(). There are several ways to do that but in C the easiest is to call getc() to remove the '\n'.

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

Since we don't have the complete code to that class it's not possible to answer your question.

line 9 is the wrong brace -- maybe just a posting error ?

line 8: this is a pointer and requires pointer notation this->

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

copy it one letter at a time, like this and also the loop needs to stop when end-of-string null terminator is found in the letter array.

char letter[8]="abcdefg";
char temp[10][2] = {0};

for(int i=0; letter[i] != 0;i++)
   temp[i] = letter[i];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>"linker error undefined reference to mciSendStringA@16"
That is a completly different problem. It means it can not find the code to that function which is probably in a library somewhere. You need to find out what library that function is in and then add it to your project.

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

The loop should keep a running total of the numbers entered

It does that

and stop when total is greater than 300

Look at the end of the do-while loop -- it is testing the wrong variable. Variable num just simply counts the number of entries made, so you would have to enter over 300 numbers before that loop stops. :-O The condition should be based on total, which is the sum of all previously numbers entered.

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

probably because you need to add a line between lines 15 and 16 that removed the '\n' (the Enter key) from the keyboard buffer. The easiest way to do that is to use ignore() method

cin.ignore();

There are cases where the above won't fix the problem, but if all you type after the digits is the Enter key then the above will work.

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

Write a program segment with a do-while loop

your program does not do that. You used a while loop, not a do-while loop. Otherwise the rest of your program looks ok.

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

pretty simple actually -- replace cout with an ofstream object. You have already included all the necessary header files so all you have to do is declare an ofstream object at the beginning of the program and use it instead of cout wherever you need to.

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

are you doing this on your own or are you reading some tutorial? Read chaper 5 of this tutorial for help on how to include resource files in a project.

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

Look at lines 128 and 130 and see if you can't figure out why the averages are zero.

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

haven't you learned anything yet? you have to declare variables before you can use them!

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

[edit]The line numbers below refer to your post #33

line 30 is showing the value of total before that value has been calculated. Why don't you move that line down to line 110. And it will show the sum of all values for not only the current sentence (or word actually) but all the words read before it. If you want to show the total for just the word that is being displayed then you will need to use a different variable. Since total is already accumulating the value in all those case statements then maybe create another int and name it something like grandTotal then sum it on line 111 and reset total on line 112. Insert the lines below at line 110.

line 111:  cout<<"Words"<<setw(30)<<"Value"<<endl<<endl;
line 112: grandTotal += total;
line 113: total = 0;

You will also have to change line 115 to use grandTotal instead of total

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

You would have to write a TSR (terminate-and-stay-resident), and I'm not sure that cmd.exe supports that like it did with MS-DOS Version 6.X and earlier.

I thought you might use one of the win32 hooks, but probably not from what I read.

Possibly a device driver or a windows service program

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

I still can't get numbers on the side? I tried using code and inline code to no avail. Sorry, I will keep looking. Thanks!

The trick is to use the languate option like this (but remove the spaces)
[ code=cplusplus]
// your code here
[ /code]

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

delete line 35, it has no useful purpose there.

variable sentlength on line 107 is declared in the wrong place -- declare it after line 29 and initialize it to 0 so that it can be used inside the loop. Then on line 35 sum up the number of characters in all sentences with the += operator.

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

cout doesn't destroy the value of the string -- your program can do lots of things with it. You could put a cout statement right after line 34 if all you want to do is display the value of the string.

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

>>. The program only shows the last word from the file(why doesn't it show all the individual words and their respective individual letter)?

because you didn't tell it to do that. Recall that the >> operator deletes the previous value stored in the string them reads the next word from the file and saves it there. If you want to display all the lines then you have to call cout just after the word is read.

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

This is how to get the line numbers
[ code=cplusplus]

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

because the length of the last word read == Retatteration -- has 12 letters and the program read 58 words, so 12/58 = 0 (integer arithmetic drops the fractional part).

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

If you want reading and evaulation to be two different functions then you need to read the file into an array of strings (probably a vector) so that the evaluation function can see them.

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

you have to also correct line 106 as I mentioned previously. sentence is only the value of the last word read from the file so its length is not appropriate for that calculation.

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

you have mismatched braces in function checkPrime() that is causing the problem

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

Actually, that loop is also wrong. Your program is supposed to be counting words, not sentences. So you need something like this

string word;

while( infile >> word )
{

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

>>numWords+=numWords;
wrong syntax. should be this: ++numWords; . And move that line outside the switch statement, between lines 33 and 34. Then delete all those other likes where that occurs. You only want to count the number of words, not the number of characters.


>>It's saying that total & numChars are undeclared.
you have them declared in the wrong place. Move lines 32 and 33 outside that loop at line 27.

>>sentence.size()/numWords<<endl;
wrong. you need to keep track of the total length of all sentences read. What you have here is just the length of the last sentence. You will need another int variable to do that.

line 30 is also wrong. It only checks for eof but never actually reads the file. Correct it like this:

while ( getline(infine, sentence) )
{
   // your code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you want to calculate the average word length then you will need another counter to sum up the length of all words read. After finished reading just divide total length by total number of words read.

>>average of the evaluation
After finished reading the file divide total by numChars

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

You need to complete that switch statement and add the cases for all the other letters. It didn't work because that sentence doesn't have an 'A'.

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

>>1. Is my declaration of each letter correct?
No. They should be declared as floats, not char, because you will need the decimal places, and make them const because their values will never change.

const float A = (1.0F * 2.0F);//value for letter A

2. use a loop to look at each letter in the string, then a switch statement to calculate the value. (probably also answers your other questions) Example:

std::string sentence = "How Now Brown Cow.";
float total = 0.0F;
int numChars = 0;
for(int i = 0; i < sentence.size(); i++)
{
   switch(sentence[i])
   {
      case 'A': 
              total += A; 
              ++numChars; 
              break;
      // blabla
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>"bypasses initialization of a local varible in function"

That error message is just telling you that you declared a variable inside a switch case statement without braces. Two ways to correct that:
(1) add the braces

switch(something)
{
     case 0:
     {
          HMENU hMenu = /* blabla */
      }
}

or declare hMenu above and outside the switch statement.

What you read in the Borland library documentation, and in the online MSDN is called a function prototype. They do not actually get executed but just tell the compiler the parameters and return value. If you are not familar with function prototypes then you need to read the link I posted because they are very basic to the C and C++ languages and you will encounter them thousands of times in the future.

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

just remove the "%s" -- its not necessary because adress is already a string that contains the filename

file=fopen(adress,"a+");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this:

fout.open("library.txt");
if( fout.is_open())
{
    fout.seekp(0,ios_base::end);
    // blabla
}

If that doesn't work then post how fout was declared.

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

A couple ways to solve your problem:

1. after opening the file call seekp(ios::end); set the file pointer to end-of-file before writing

2. Add the ios::ate flag to the open statement: fout.open("library.txt", ios::out | ios::ate);