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

>>should I include that as an extern variable as well?
No. All you have to do is include the head file that defines the struct at the top of example.h. And don't forget to use code gards in both head files.

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

Is it even possible to change thread titles beyond marking them as solved?

Yes, mods can change them. And I will change this one in January 2013 if I'm still around. :)

[edit]Oops! No I can't because I don't monitor Geek's Lounge. Here I'm just like anyone else (almost)[/edit]

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

Only free the rows that are malloc()'ed. But if you declare/initialize tab_veld as previously posted then malloc() will not complain about giving it a NULL pointer. So if you are getting general protection error then those pointers have either not been initialized to 0 or had already been free'ed. It's always good to reinitialize pointers to 0 after freeing them to avoid that problem.

free(tab_veld[y]);
tab_vels[y] = 0;

>>Sorry for those weird variable names, i'm from belgium and those are in dutch.
No need for apology, we don't all live in English-speaking countries.

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

If all you want them to hold is a single character then you don't need them to hold strings. You can simplify the table to this: char* tab_veld[80]; which is an array of 80 pointers (or 80 rows of unspecified number of columns). If you want each row to have 100 columns, then tab_veld[0] = malloc(100); Each column can hold one of the 5characters you previously specified, that is 'X', '|', 'J', '-', or the space ' '. Note that this are NOT strings, but single characters.

char*tab_veld[80 = {0};
// assuming [b]lengte[/b] is the number of columns in each row
 for(y=0;y< 80; ++y){
       tab_veld[y] = malloc(lengte); 
       memset(tab_veld[y], ' ', lengte); // set each column in this row to a space
 }
// I don't know what posvisser means so I can't tell you if the next two lines are right or wrong.  But what you want to do is just set a sincle cell to a single character.
 tab_veld[0][posvisser] = 'X';
 tab_veld[posvishaak][posvisser] = 'J';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you new to c and c++ languages? You are asking a 1st semester student type of question. If you are then attempting to write an MFC program is way beyond your current level of knowledge. Get an introduction to computer programming book and start studying from page 1. Then in a year or so you will be ready for that MFC program.

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

what makes you think you can compare integers and strings ? Ain't going to work. If the strings contain numeric digits then convert them to integers before doing the comparison.

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

Great going, and good luck in the future. Hope you passed the class with flying colors :) :) :)

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

>>i mixed with a c++ clas. right?
Yup.

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

cbSize is a member of a structure that you set to the structure size before calling win32 api functions with it. For example:

struct foo
{
    unsigned int cbSize;
    // blabla
};

struct foo MyStruct;
MyStruct.cbSize = sizeof(struct foo);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

CStrings are required when interacting with MFC objects such as CEdit, CListBox, etc. Other than that, you can use whatever you like. Using std::string might bloat your program up a little though. If you are concerned about the size of the final executable program then try to avoid std::string.

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

>>One thing I'm confusing. I'm using a string type variable, not a CString. Actually in an MFC application.

What's so confusing about that? Just because you have an MFC project doesn't mean you can't use the c++ STL and other classes such as io streams. I like MFC and CString for interacting with MFC object. But I find std::string can be more useful for other things. And I normally never use CFile class because it sucks cannel water. fstream is much better, unless you want to serialize MFC objects.

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

>>yeah, with that values. I'm still having a hard time figuring out because the ini file that I generated in windows is compose of wchar_t characters

Ohhh that is not very good. The sizeof(wchar_t) in Windows compilers is not the same as in *nix compilers. The last time I checked Windows = 2 (short int) while *nix was 4 (long). So to read the file in *nix you will probably have to read each character as a short then convert it in memory to wchar_t (a long).

I doubt you will find any *nix library that will read that windows-generated file because of the size problems I mentioned above. But what you could do is write a program to convert the entire file then use one of those library functions to parse it.

jaepi commented: Lean Mean Detailed Info Producing Machine +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>string filePath = FullPath.GetFileTitle();
std::string does not have a method called GetFileTiele(). That is in the CStirng class :)

you can use stringstream class

#inlcude <sstring>
...
int ID;
stringstream stream(groupID);
stream >> ID;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

See line 11: you changed the declaration of filenames from an array of pointers to a simple pointer that is no longer an array. Change it back the way it was in your original post. You also have to change line 21 to use the array index.

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

>>When I tried this, I got two warnings:
>>1. assignment makes integer from pointer without cast
>>2. passing arg 1 of 'strcpy' makes pointer from integer without cast

Post code because what I posted is correct.

>>I have it starting at 2 because I only need the filenames, not the '.' and the '..'
Oh I see. You are correct. Normally we would not put them in the list.

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

Glad to have helped.

AD

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

line 97: >>while (checkPlayed (guess));
It gets suck here sometimes. In my testing it was after I entered the 3d number. Very probably because of that semicolon at the end of the line.

[edit]See now, if you had learned to use your compiler's debugger you could have found this error two weeks ago. It took me all of about 10 minutes to find the problem.[/edit]

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

yes, I continued and after the 3d entry it stopped. I'm going to run the debugger to see what is causing it, my guess is the program is trashing memory.

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

Every MS-Windows program (per-module bases) has an HINSTANCE value. Its like a numerical ID that the operating system uses to keep track of the processes (programs) that are running. That's all it means. If you are playing two different games on your MS-Windows computer each instance of each game will have its own unique HINSTANCE value.

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

I compiled with VC++ 2005 Express and it ran ok. Here is the output

Tic Tac Toe
1 | 2 | 3
- - - - - -
4 | 5 | 6
- - - - - -
7 | 8 | 9

Human:1
x | |
- - - - - -
| |
- - - - - -
| |

Computer: 9
x | |
- - - - - -
| |
- - - - - -
| | o

c= 2
Human:

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

>>What is pre-module basis
The HINSTANCE is used to identify a specific process (program that is running). Program A will have a different value of HINSTANCE than program B. Or that's the way its supposed to work.

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

>>filenames = (char *) malloc(sizeof *filenames);

That solves nothing. what is sizeof(*filenames) ?? Answer: number of bytes allocated to the array, not the number of bytes needed to copy d_name into the array. Here is what it should be: Note that you have to use the i counter because filenames is an array of pointers. And, in C language, you do not have to typecase the return value of malloc. Required in c++, but not in C.

filenames[ i ] =  malloc(strlen(dir->d_name)+1);
strcpy(filenames[i],dir->d_name);

line 33: >> for (a = 2; a < i; a++){
why is that loop starting with 2 instead of 0.

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

To remove punctuation you will normally have to rewrite the entire string to avoid the many problems with modifying string literals passed to the function. Just iterate through the string one character at a time and copy the character to the new string only if it is not a punctuation character.

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

line 23 needs to call malloc() to allocate memory for the name then call strcpy() to copy the name. Hardcoding the number of filename pointers in your program is ok only if you know in advance the maximum you will need. But what happens to your program if there are 10 filenames in that directory? Or 100 filenames ? In those cases you will want to use a linked list of names.

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

The problem is that SSN and GRADE have not been declared yet. To fix move lines 24 thru 32 up to just under line 13.

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

If you want to eliminate the lines where the name is duplicated then you will need to read the file into an array so that the program can check if the name has already been read. In c++ the vector class is the most convenient way to create the array. Below is one way to do it

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

struct student
{
    string sex;
    string grades;
    string name;
};


int main()
{
    vector<student> studentList;
    student stdnt;
    cout << " Sex        Answers                  Name      " << endl;
    cout << " ---     --------------        --------------- " << endl; 
    //string line;
    std::ifstream in("TextFile1.txt"); 

    if(!in)
    {
        std::cout<<"Could not open file\n\n";
        return 1;
    }
    // read the data file into an array of structures
    while( in >> stdnt.sex >> stdnt.grades )
    {
        getline(in, stdnt.name);
        vector<student>::iterator it = studentList.begin();
        bool found = false;
        // search the array for this student
        for( ; it != studentList.end(); it++)
        {
            if( it->name == stdnt.name)
            {
                found = true;
                break;
            }
        }
        // if not int the array, then add it
        if(found == false)
            studentList.push_back(stdnt);
    }
    // all rows in the file are now read, so just output the data
    vector<student>::iterator it = studentList.begin();
    for( ; it != studentList.end(); it++)
    {
        cout.setf(ios::left);
        cout << setw(10) << "  " + it->sex << setw(20) << it->grades << setw(15) << it->name << "\n";
    }

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

line 33: sex[3] does not exist. That array has elements numbered 0, 1 and 2. There is no element 3. And that loop isn't necessary anyway. The array can be initialized to 0 when declared int array[3] = {0}; . Do the same with all the other arrays.

line 32: why? it has no purpose, so just delete it.

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

I tried it with the corrections you suggested and know the program won't read the file or at least it won't cout any of the information.

Post code please -- I live only about 30 miles from you but my eyesight isn't that good :)

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

Please post a line or two from the data file.

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

Looks ok to me. What compiler and what is the error message?

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

Your program has some mismatched { and } bracket. Proper code alignment should show these up right away. The function at line 150 has this problem.

line 43 is syntax error. You did not specify a parameter for the time() function.

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

i read from the file using this:

fscanf(in, "%[^:]:%[ ^:]:%[ ^:]:%d:%lf", empNum, lName, fName, &pGrp, &hrsWorked);

I tested this and it works: fscanf(in, "%[^:]:%[a-zA-Z0-9]:%[a-zA-Z0-9]:%d:%lf", empNum, lName, fName, &pGrp, &hrsWorked)

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

I never type it manually -- just click a link. No point in wearing out my fingers :)

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

>>My question is ,is it really addres or i am wrong informed and if it addres how to use in Dev-C++?is it possible?

Yes, as far as I know, those are the actual memory address. You can not access them directly with any 32-bit compiler unless you write your own device driver as Vijayan posted.

What is it that you want to do? There is probably another way to do it without accessing actual memory locations.

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

>>Is that what I want there?

Probably not. The problem is somewhere else. Remember that after executing that function the last one or two locations in the new array do not contain valid data. How many elemenets are invalid depends on the difference between the original size and the new size.

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

That loop should copy the original number of entries, not the new number, and use < operator, not <=.

void DateArr::resize(int newSize)
{
	Date* newTempArr;
	newTempArr = new Date[newSize];
	for (int i=0; i < size; i++)
		newTempArr[i] = arr[i];
	size = newSize;
                delete[] arr;
                arr = newTempArr;

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

>>error: glibtop.h: No such file or directory
Either you don't have glib installed on your computer or you need to tell your compiler where to find it.

>>Or to give me another idea like how to get info from /proc/cpuinfo
Don't know, but someone else probably does.

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

you could also use c++ std::map class, but may or may not be too advanced for you at this time.

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

elite: you are still wrong! That does indeed copy the pointers but the class needs its own copy of those strings because the calling function may change the string contents. If you need to use character arrays then declare them as in the original post but in the class constructor you have to call strcpy to duplicate the string so that the calling function can not change the string contents.

My personal preference is to use std::string class instead of character arrays, but the OP may not be able to do that.

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

elete: lines 43, 45 and 47 of the code you posted are wrong. C-style character arrays can not be copied like that. You have to call strcpy function to copy them.

tones:

line 33: close, you forgot to make the variables pointers, see the stars here: Employee(char* last_name = "", char* first_name = "", char* ss_num = "0", double salary = 0, int years_employed = 0);

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

you could use an array of structures

struct phrases
{
    char* correct;
    char* response;
};
phrases  ph[] = {
   {"CU","See You\n"},
   {":-)", "I'm happy\n"},
 // etc
};

   cout << "Enter phrase>";
    cin >> input;
  for(int i = 0; i < sizeof(ph)/sizeof(ph[0]); ++i)
  {
        if(stramp(input, ph[i].correct) == 0)
        {
             cout << ph[i].response;
             break;
        }
   }
vmanes commented: Clever solution. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there any way to easily change what I have, to what I am supposed to have?

Depends on your definition of easily :) It will require some rewriting of each of those cout lines, but shouldn't been too difficult. Something like below (not compiled or tested)

#define PRINT_DOT (cout << ".";)
#define PRINT_DASH (cout << "-";)

...
case A:  PRINT_DOT PRINT_DASH cout << "\n\n"; break;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this: It does a case-sensitive comparison, such as "Rudolf" is not the same as "rudolf"

#include <iostream>
using namespace std;

int main()
{
    char input[20];
    char correct [] = "Rudolf";
    cin >> input;
if (strcmp(input, correct) == 0)
    {
              cout << " correct";
    }
    else
    {
              cout << "incorrect";
     }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just make sure you use a Nightly Build!

why? does the compiler change from day-to-day?
[edit]After reading the link you posted I see what you mean. Yes the compiler might change on a daily basis[/edit]

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

1. you can not initialize c-style character arrays like you are trying to do in the class constructor. My suggestion is to declare them as c++ string objects. If you can not do that then to initialize the arrays to empty string just set the first byte to 0, like this: last_name[0] = 0; line 30: you have to add the parameter names as well as their data types, and declare them as const because they are unchangeable by the setName function. void setName(const char* LastName, const char* FirstName); You need to change the other methods in lines 31-34 the same way.

line 40: too many parameters -- see line 30

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

Here is an introductory tutorial -- and you can keep your free book

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

Will that work for:
John Smithers 2031 West Alberta Street Sioux Falls South Dakota 65565? :icon_rolleyes:

Yup, works for that too! It just won't give the OP the result he wants :)

while( getline(cin,name) )
{
    getline(cin,street);
    // etc
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is using '#' to deliniate lines required by the assignment or is it something you dreamed up on your own?

while( cin >> name >> street >> city >> state >> zip)
{

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

Commenting code is very good -- but commenting with wrong information is very very bad.

>> // Clears the unused characters from the buffer
that function does not do what you said it does. The clear method clears error bits.

>> Ignores the buffer generated by cin.clear
Doesn't do that either. cin.clear() doesn't create a buffer

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

>>and any other pointers with how I should code the else porition on my operator +
The easiest way is to use the mktime function in time.h. Populate a struct tm structure with the year, month, and day + days_to_increment, then call mktime() to normalize the data. Upon return the tm structure will be corrected.