Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
while(!fis.eof())
    {
	lines2++;
	fis >> str;
    }

two problemss:
1) that counts the number of words, not lines. If you really want lines then call getline()

2) That will count the last line/word twice because eof() doesn't work lilke that. Here's how to code the loop

while( fis >> str)
   ++lines2;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem may be in another function. Remember, the keyboard buffer is global to the entire program, not just one function.

Also, that function should probably strip off the '\n' character at the end of the buffer, otherwise your program may not process the contents of the buffer correctly.

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

There is no ansi c standard way of flushing the input stream. fflush(stdin) is compiler specific becaue fflush() is only guaranteed to work on output streams such as stdout.

If you want a non-standard way to do it you could use fflush(stdin) or functions from conio.h such as

while(_kbhit() ) // while more keys in the keyboard
    getche(); // remove the key

>>The first problem I ran into was that stdin always had '\n' in the buffer
That normally happens only after calling scanf() to get numeric input. fgets() will remove the '\n' and append it to the end of the input buffer if the input buffer is large enough to hold it.

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

you can't call the constructor like you did in main())

int main()
{
	Bicycle myBike(24,17); 
	myBike.printBicycle(); 
	
	return 0; 
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) you could store them in different directories.

2) extract a file, rename it, then extract another file. Do that for each of the zip files.

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

you should have received a compile-time error on that line because it's syntically incorrect -- _T( macro is never closed, needs a ) before the comma.

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

>>So if i were to print an my array of names, say for a roster of passengers on an airplane would this code be correct?

Did you run that code? Did it work the way you wanted it to? Answer those two questions "YES" and you will have the answer to your question.

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

what you need is an array of strings so that the program can keep all the strings until ready to print them all out

const int MAXSTRINGS = 10; // hold max of 10 strings
const int MAXLENGTH = 25; // maximum of 40 characters per string
char firstname[MAXSTRINGS][MAXLENGTH];
char lastname[MAXSTRINGS][MAXLENGTH];

how you will have to index into those arrays

int i;
for(i = 0; i < MAXSTRINGS; i++)
{
    printf("Enter a first name\n");
    fgets( firstname[i], MAXLENGTH, stdin);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>printf("%s %s %d %d\n", coltitle[0], coltitle[1], table[k][0], table[k][1]);

coltitle is just an array of one character, not an array of strings. It was declared as char coltitle[2]; "%s" tells printf() that the next argument is a null-terminated string. But what you sent it was just a single character -- coltitle[0].

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

Just use two arrays and print both at the same time

char names[20][80]; // array of characters
int scores[20];

// put this line in a loop.  You can put as many arguments to printf() as you want.
fprintf("%-20s %-10d\n", names[i], scores[i];
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't, and we normally don't either unless it villates one or more of the DaniWeb Rules.

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

There is only one thread. The thread is used to continually run and to update the window in the main() section of the program. Also making hWndCurrentTime global does not work either. It actually still shows as undefined when running the thread.

>> hThread = CreateThread(NULL, 0, ThreadTime, NULL, 0, &dummy);

Nope, your program has two threads. The thread with winMain() is a thread and ThreadTime() is the second thread. Every windows program has at least one thread.

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

It has been my experience that windows can only be updated in the thread in which they are created. What I have done to resolve your problem is for thread2 to send a message to thread1 so that the window can be updated by thread1. See PostThreadMessage()

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

All you have to do is put that code in a loop. Simple.

for(i = 0; i < 10; i++)
{
if( score[i]>79 && score[i]<101 ) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tA"<<endl;
} else if( score[i]>74 && score[i]<80) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tA-"<<endl;
} else if (score[i]>69 && score[i]<75) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB+"<<endl;
} else if( score[i]>64 && score[i]<70) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB"<<endl;
} else if (score[i]>59 && score[i]<65) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tB-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tB-"<<endl;
} else if( score[i]>54 && score[i]<60) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC+"<<endl;
} else if (score[i]>49 && score[i]<55) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC"<<endl;
} else if( score[i]>44 && score[i]<50) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tC-"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tC-"<<endl;
} else if (score[i]>39 && score[i]<45) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tD+"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tD+"<<endl;
} else if (score[i]>34 && score[i]<40) {
  cout<<i+1<<"\t"<<score[i]<<"\t\tD"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tD"<<endl;
} else {
  cout<<i+1<<"\t"<<score[i]<<"\t\tF"<<endl;
  outfile<<i+1<<"\t"<<score[i]<<"\t\tF"<<endl;
}

}
ARYT commented: "do-while"??? :( +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The vector isn't expecting a pointer. Change the vector to this if you want pointers: vector<Shape*> shapes;

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

you can also use setw() to specify the width of the print field cout << left << setw(20) << "Number" << setw(25) << "Numerical Scores" << setw(15) << "Grade" You also will have to include <iomanip> header file for the above to compile.

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

You are not listening -- I already explained that 6 hous ago in my post #3 to this thread.

As I alredy mentioned and posted you have to allocate memory for those pointers in that char*pointer[10] array. The way you have written it all 10 pointers point to the same address. What you need is for each pointer to have different, unique addresses. The only way to accomplish that is using the new operator.

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

Thanks for your patience, but we cannot use "string" and "struct" yet.
.

replace string with character arrays and replace the struct with two arrays, one array of ints and the other of charcter arrays.

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

fgets() function appends '\n' to the end of the string, so you either need to strip it from the input string or not print '\n' (endl) in the output string.

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

you failed to implement everything I said before. Re-read my previous post and compare with what you posted. You are trashing your program's memory with that fgets() line

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

Ok, normally wouldn't do it but this thread is getting pretty long and you have tried pretty hard. Here is how I would code it.

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

struct grades
{
    int score;
    string grade;
};
int lower_limits[10] = {
    80, 75, 70, 65, 60, 55, 50, 45, 40, 35
};
string letters[10] = {
    "A", "A-","B","B-","C","C-","D","D-"
};

int main()
{
    const int MAXGRADES = 10;
    struct grades theGrades[MAXGRADES];
    for(int i = 0; i < MAXGRADES; i++)
    {
        cout << "Enter score #" << i+1 << "\n";
        cin >> theGrades[i].score;
        // now find the grade
        for(int j = 0; j < 10; j++)
        {
            if(theGrades[i].score > lower_limits[j])
            {
                theGrades[i].grade = letters[j];
                break;
            }
        }
        if(theGrades[i].grade == "")
            theGrades[i].grade = "F";
    }
    for(int i = 0; i < MAXGRADES; i++)
    {
        cout << "score " << theGrades[i].score << " = " << theGrades[i].grade << "\n";
    }

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

lines 16, 17 and 18: too many loops and too many fgets() function calls. The while statement will read the entire file.

Also you can use retazce like that because its just an array of pointers that point to nowhere. You have to first read the line into a valid buffer, allocate space in retazce, then copy to retazce, like below

char oneline[255];
while(fgets(oneline, sizeof(oneline), pFile)!=NULL) { 
   retazce[line] = new char[strlen(oneline)+1];
   strcpy(retazce[line], oneline);
   line++;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

change the reference to a pointer and see if that solves the problem.

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

if grade is declared as an int then you need to typecast it when printing it cout << (char)grade It might be cleaner if you had an array of grades similar to the scores so that you could figure out all the grades first and then print them in a nice tidy loop.

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

when you add the files to the project as I previously explained and you select Build --> Build Solution the IDE will compile all the *.cpp and *.c files then link the all together into one executable program. Its really not at all that difficult to do.

In the file that contains main() function you will probably have to declare functions in other files as extern, if you don't do that then the compiler will complain about undeclared functions

// main

extern int foo(); // located in another *.cpp file

int main()
{
    foo(); // call the function in another file
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I've tried that before (putting files in different folders) with that compiler and vc++ 2008 express. It can be done, but a little tricky.

For *.cpp and *.c files: open Solution Explorer, right-click Source Files, then in the dropdown menu select Add --> New Filter. That will add a new folder under Source Files folder. Do the same with with the Header Files folder. After that you can add existing files to those new folders -- right click on the folder then select Add --> Existing Item then navigate to the items you want to add to that folder.

When you compile the solution you have to be careful about the location of the includes that are in those *.cpp and *.c files because for locally created header files they won't be in the same place as they would have been had you just put the source files directly in the Source Files folder.

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

how to do that will depend on the compiler, each one is a little different.

Do you mean you want to put the source files, such as *.cpp, *.c, and *.h, in different folders?

dvsConcept commented: very helpful +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>and wont feel like counting out up to 800,000 characters to find out.
LOL :)

>>So how do i make the file pointer to the beginning of the file and clear all errors

infile.seekg(0, ios::beg);
infile.clear();

You should start reading about the various functions available to fstream class. Here is one good source.

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

Here is the output I got

1         George Washington          Fed   	4/30/1789	3/3/1797	2/22/1732	VA		12/14/1799	VA		1
2         John Adams                 Fed   	3/4/1797	3/3/1801	10/30/1735	MA		7/4/1826	MA		1
3         Thomas Jefferson           D/R   	3/4/1801	3/3/1809	4/13/1743	VA		7/4/1826	VA		1
4         James Madison              D/R   	3/4/1809	3/3/1817	3/16/1751	VA		6/28/1836	VA		1
5         James Monroe               D/R   	3/4/1817	3/3/1825	4/28/1758	VA		7/4/1831	VA		1
6         John Quincy Adams          D/R   	3/4/1825	3/3/1829	7/11/1767	MA		2/23/1848	MA		1
7         Andrew Jackson             Dem   	3/4/1829	3/3/1837	3/15/1767	SC		6/8/1845	TN		1
8         Martin Van Buren           Dem   	3/4/1837	3/3/1841	12/5/1782	NY		7/24/1862	NY		1
9         William Henry Harrison     Whig  	3/4/1841	4/4/1841	2/9/1773	VA		4/4/1841	OH		1
10        John Tyler                 Whig  	4/6/1841	3/3/1845	3/29/1790	VA		1/18/1862	VA		1
11        James K Polk               Dem   	3/4/1845	3/3/1849	11/2/1795	NC		6/15/1849	TN		1
12        Zachary Taylor             Whig  	3/5/1849	7/9/1850	11/24/1784	VA		7/9/1850	KY		1
13        Millard Fillmore           Whig  	7/10/1850	3/3/1853	1/7/1800	NY		3/8/1874	NY		1
14        Franklin Pierce            Dem   	3/4/1853	3/3/1857	11/23/1804	NH		10/8/1869	NH		1
15        James Buchanan             Dem   	3/4/1857	3/3/1861	4/23/1791	PA		6/1/1868	PA		0
16        Abraham Lincoln            Rep   	3/4/1861	4/15/1865	2/12/1809	KY		4/15/1865	IL		1
17        Andrew Johnson             Dem   	4/15/1865	3/3/1869	12/29/1808	NC		7/31/1875	TN		1
18        Ulysses S Grant            Rep   	3/4/1869	3/3/1877	4/27/1822	OH		7/23/1885	NY		1
19        Rutherford B Hayes         Rep   	3/4/1877	3/3/1881	10/4/1822	OH		1/17/1893	OH		1
20        James A Garfield           Rep   	3/4/1881	9/19/1881	11/19/1831	OH		9/19/1881	OH		1
21        Chester A Arthur           Rep   	9/19/1881	3/3/1885	10/5/1829	VT		11/18/1886	NY		1
22        Grover Cleveland           Dem …
rickster11 commented: Thanks, helped a bunch +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

For some reason ifstream doesn't work with that file. Change it to FILE pointer and it works ok

//    ifstream inPresFile("presfile.dat");
    FILE* inPresFile = fopen("presfile.dat", "rb"); // <<< THIS

    if (!inPresFile)
    {
        cout<<"File could not be opened"<<endl;
        exit(1);
    }

    heading();
    
    int counter = 0;
    //for (int counter=1; counter < 43; counter++)
    while( fread(reinterpret_cast<char *> (&presRecord),1, sizeof (presRecord), inPresFile))
    {
        ++counter;
        //nameField[0] = '\0';
        //inPresFile.read(reinterpret_cast<char *> (&presRecord),sizeof (presRecord));


        strcpy (nameField,presRecord.firstName);
        strcat (nameField," ");
        strcat (nameField,presRecord.lastName);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 10: that function gets the file size the hard and slooooow way. All you have to do is seek to the end of file then call tellg() to get the file size -- only two lines of code :)

If you want to leave that function as it is, then you will have to move the file pointer back to the beginning of the file and clear all errors before leaving the function. If you don't then the program won't be able to read the file any more.

>>But the bookFile character(c) is blank.
Look at the file with Notepad.exe (or some other text editor) and find the character your program should find. Is it a space?

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

post new code.

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

It's Ok. I know the rules.

Apparently not well enough to add code tags

[code=cplusplus] // your code here

[/code]

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

your loop is doing too much work.

char codes[] = "qwertyuiop";

string dCode = "wtu";  // hard-code search value

for(int i = 0; i < dCode.size(); i++)
{
    for(int j = 0;  codes[j] != 0; j++)
    {
          if( dCode[i] == codes[j])
          {
              cout << codes[j-1];
              break;
          }
    }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>else if(currentChar == "" ) cout << " " << endl;

change that "" to " " (with a space between the quotes)

else if(currentChar == "" ) cout << " " << endl;
	else if(currentChar == ",") cout << "," << endl;
	else if(currentChar == ".") cout << "." << endl;
	else if(currentChar == "!") cout << "!" << endl;
	else if(currentChar == "?") cout << "?" << endl;

why not just shorten tat to this: else cout << currentChar << endl;

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

>>That's where the guards (the #ifdef stuff) are for right?

Nope. The guards prevent the same include file from being processed more than once. For example:

#include "element.h"
#include "element.h" // this one will be ignored

Your program had a different problem. The preprocessor attempted to process the line that used element *elm but class element had not been fully defined yet. With forward references the class doesn't have to be fully defined in order to declare a pointer to it.

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

>>Why is element not declared?
Because you have recursive includes -- each header file includes the other.

In eventhandler.h try this:

#ifndef EVENTHANDLERH
#define EVENTHANDLERH

class element;  // forward declaration of class

enum events {onClick, onHover};

typedef struct eventHandlerT {
    void(*func)(element *elem);
    events eventType;
} eventHandler;


#endif // EVENTHANDLERH
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I assume table is an array of integers? Yes?

If you want the numbers aligned up right then add width fields printf(output, "%10d %10d", ...) will print them right justified in a 10 character field. If you want them left justified then add - character printf(output, "%-10d %-10d", ...)

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

open the file
read each line
for each line read, search the line for the given word. If you ust std::string to hold the line then use it's find() method. You will probably first have to convert the line to all lower or upper case so that you get case-insensitive compares.

If the word is found then just add it to the array. std::vector is recommended here because it make that process pretty simple.

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

Read the list of format specifiers for printf() function. You will see that %d is decimal, %o is octal and %x is hex. With that information you should be able to write your program in just a few lines of code -- one line of code for the actual print statement.

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

It might be your computer, your window resolution setting, or your operating system. install another font perhaps? search www.codeproject.com or some other similar sites for example code.

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

The "thing" at the start is probably a binary character that tells programs the file is UNICODE format -- its called "UNICODE signature". When you click this link scroll down the page until you find the section titled "unicode signature". Please feel free to read the rest of the page too :)

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

Post your code because my eyes aren't good enough to see what's on your monitor.

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

1/3 is integer division which results in 0. Try 1.0/3.0 to get float division.

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

>> telling you if you give $19 , she will tell you 6 lucky numbers which can make you win million dollers

:) what a scam ! does she guarentee those results?

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

>>[pid,perm,dir,owner,group,size,date,file] = strtok(s," ");
What in the world are you trying to do here? strtok() only returns one string, not multiple strings.

pid = strtok(s," "); // first time
perm = strtok(NULL, " ");
dir = strtok(NULL, " ");
// etc etc for each of the others
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is a great deal of truth in that video. I have dish network tv with over 100 channels to choose from, and there are days when there isn't a thing that I want to watch.

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

1) You can post feedback in Daniweb Community Feedback forum.

2) Check your Profile page (see CONTROL PANEL at the top of each DaniWeb page) to see if email notifications have been enabled.

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

So you mean Narue could be intolerable when it comes to get in a relationship with her? Might she just be a good programmer, not a partner ? :)

I doubt that is the case. Narue is the mother of at least one child that I know about, and I assume she is also married. So you see, talented and intelligent women can, and often do, have meaninful relationships.