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

>>I hope you've either found it interesting, or you're getting paid to do this.
Interesting, yes. Getting paid, no.

>>there are clearly several ways to skin this cat
For those who don't know, skin a cat doesn't mean an animal. A cat refers to a Catapiller heavy duty dirt moving equipment. My dad did that for about 50 years and I heard that phrase thousands of times. Catapiller is a brand name of the equipment.

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

you use VARIANT just as you would any other structure.

VARIANT foo()
{
    VARIANT vt;
    vt.vt = VT_I4; // long integer
    vt.llVal = 123;
    return vt;
}

int main()
{
    VARIANT Var = foo();
    cout << "type = " << Var.vt << 
        " long value = " << Var.llVal);

    // or if you don't know the type of variant
    switch(Var.vt)
    {
    case VT_I2: cout << "integer"; break;
    case VT_L4: cout << "long"; break;
        // etc
    }
    return 0;
}

>>My initial question about a variant return type was not about a function that returns a type named VARIANT. It was about a function that could return any of several types.

That is not possible in C or C++ without using a structure or class. The AnyType class in Boost or something like VARIANT structure are the only two ways to achieve your design. You could use c++ templates but if you can't afford 16 bytes for VARIANT then you can afford the duplication that templates will create, which is a great deal more than 16 bytes.

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

what compiler are you using and what operating system are you working with. I know for a fact that Microsoft added exception handling in eVC++ 4.0 which is pretty old now.

>>I definitely cannot afford to turn all my variables into VARIANT types. A union of all types takes the storage space of the largest type. That is far too wasteful.


cout << "sizeof(VAIRIANT) = " << sizeof(VARIANT) << "\n";

The result of the above is 16. If you can not afford 16 bytes then you do have a very difficult time ahead of you.

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

I don't see why someone couldn't write a function named dialog() for *nix -- it obviously is not the same as a MS-Windows DialogBox. Do you have to source code for that function? If not then your only recourse is to read the documentation, and you say there is none. If you are using some sort of GUI libraries such as QT then you will find the documentation at their web site.

>>I think this is some type of NCURSES or other aftermarket implementation.
Well, what are the libraries that your program has to link with? Those should tell you where the function is.

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

your while statement is incorrect

while( infile>>thisdate )
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

worked for me. Here's the code I used. I made a minor change at line 291 but that was only for debugging. There are several other problems that I didn't mention, such as use of gets() function. You should use fgets() instead because gets() can destroy your program if you type more characters then the input buffer can hold. For example: Acct is 6 characters, try typing this number: 123456789012345 <Enter> and see what will happen.

#include   <stdio.h>
#include   <string.h>
#include   <stdlib.h>


#define MAX 100


int menu(void);
int display(int i);
void customer_search(void);
void AccNo_search(void);
void enter(void);
void save(void);
void load(void);

struct catalog
{
       char name[80];
       char AccNo[6];
       char address[80];
       unsigned date;
       unsigned char month;
      
}*cat[MAX];

struct bank
{
        char BankName[20];
        unsigned LastAccNum;
        unsigned sortCode;
        
}*bank[MAX];

int top = 0;


int main(void)
{
              int choice;
              
              load();
              
              do
                {
                         choice = menu();
                         
                         switch(choice)
                               { 
                                       case 1: enter();
                                            break;
                                       
                                       case 2: customer_search();
                                            break;
                                            
                                       case 3: AccNo_search();
                                            break;
                                            
                                       case 4: save();
                               }
                }
       
       while(choice !=5);
system("PAUSE");
       return 0;

}   
            
            
            /* Return a menu selection*/
            
int menu(void)
{
    int i;
    char str[80];
    
         printf("\t\n\aEircom Billing System\n\n");             
         printf("1->Add Customer\n");
         printf("2->Search by Name\n");
         printf("3->Search by Account Number\n");
         printf("4->Save added Customers\n");
         printf("5->Quit\n");     
              
           do
                {
                                 printf("Make your selection:  ");
                                 gets(str);
                                 i = atoi(str);
                                 printf("\n");                        
                } while(i < 1 || i > 5);   
                
           return i;
}                    
                                      
    /*Enter customer into file */
    
    
void enter(void)
{
     int i;
     char temp[80];
     
     
     for (i = top; i<MAX ; i++)
            {
                                    
                   cat[i] = malloc(sizeof(struct catalog));
                   
                          if(!cat[i])
                                 {
                                                 printf("Out Of Memory\n");
                                                 return;
                                 }
                  
                 printf("Enter customer name …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 87: never ever use gets() for anything because it can overwrite the input buffer and cause your program to crash. Instead, use fgets() to limit the length of the text.

lines 292 and 293 need braces around that multi-line if statement. That's why your program just exits.

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

>>One problem is the the programs stops at a certain point which is noted in the code
Please identify the line number. Did you forget to mark it because I don't see it.

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

This is not a standard MFC class so you will have to read the docs from wherever you got it. Most likely from here.

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

>>cant detect well the problem..
Neither can we since we can't see your computer's monitor and code.

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

you could do a remote login on the remote computer, assuming you have a user name and password on that machine. I've seen this done by network administrators at my old office, but I don't know exactly how they did it. I suppose another way is to use PCAnywhere by Symantic.

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

I'll repeat myself -- you did not include the <string> header file -- or at least you didn't show it in the code you posted.

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

I think you get a couple rep points for every 1,000 posts. As far as I know there are no rep points based on length of membership. Post frequently in the technical forums and your rep points will probably go up faster.

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

>>error C2679: binary '>>' : no operator found which takes a right-hand operand of type
>>'std::string' (or there is no acceptable conversion)

you forgot to include <string>

line 30 of the code you posted: the iterator iter has never been set to anything, so that loop won't work right.

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

No it doesn't make sence. What compiler are you using ? No compiler in the world would have given you a clean compile with those errors in it. You just did not pay any attention to the errors your compiler gave you.

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

My program works properly under windows, however, it seg faults when I try to compile/run it under linux.

So, how did you get the executable program when there were compile erorrs? No respectable compiler produces the executable under that condition. Do you not look at the messages your compiler produces?

But, like I said, it does work under Windows, just not Linux.

The exact same code ? Is yes, then its impossible you could have gotten a clean compile.

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

no -- the rc file is compiled and attached to the *.exe. If you need to change one of the resources in it during runtime you will have to make in-memory changes.

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

Several ways to achieve that. Read this article

shaikh_mshariq commented: Helped a lot +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's Fawlty Towers, not Ivory :)

You're right -- its halarious anyway. Its been several years since I have seen it. Get it once in awhile on BBC America TV channel.

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

You apparently created a Windows application, not a Console application. The easiest correction is to start a new console project then copy what you have done into it.

And your program must have a main() function.

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

I think the problem is line 21 of the header file -- you have to have a semicolon at the end of the class. Put a semicolon after that closing brace.

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

Where do I put the for-next loop?? Within the constructor??

Well Duuuah! of course you put it in the contructor -- afterall that was your original question wasn't it.

delete line 70 of your original post (I added line numbers to make it easier to refer to it). Then put a for-next loop there.

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

Duoas already told you how to do it -- create a for-next loop and set each element to 0

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

There are lots of examples right here at DaniWeb. Just search for ifstream and getline()

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

int main()
{
   vector<string> strings
   string line;
   ifstream in("filename");
   while( getline(in, line) )
        string.push_back(line);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sadly, the c++ compiler i have to use at uni must use those headers, as it isn't a very new program. So I do have to use them :(

Oh, that's unfortunate that your school is making you learn something that will never be used in the real world. We tossed out those compilers 15 years ago.

I've never come across any examples of this before.

Well, then you didn't read the POST #6 very well, if at all, because it has exactly what you need.

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

House.

House isn't a sitcom.

My varorite sitcom from UK is Ivory Towers, although Red Dwarf was very good too. From USA is I Love Lucy and The Jeffersons. I don't like any of the current ones.

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

you don't need lines 25-29 to zero out the array. Do it when the array is declared, like this: int matrix[101][5] = {0}; >>What alterations/additions do I make to the code to import the .txt file into the array?
Code that reads the text file. Start by deleting lines 1 to 3 -- al those files are obsolete in C++. Most likely all you need is this:

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

Next declare an ifstream object Then in a loop read the integers into the array. See Vernan's post #6 above, which is an example of how to read the file.

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

line 1: you forgot to add the includes

you can delete lines 17 and 21, and just use variable k in line 20.

Here is a simplified version of your program

#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<string> strings;
bool done = false;

int main()
{ 
string sentence;
sentence = "This is sentence Two\n";    
strings.push_back("This is sentence One\n");
strings.push_back(sentence);
strings.push_back("This is sentence Three\n");
for(int k = 0; k < 3; k++)
{
    cout<< strings[k] << "\n";
}
system("pause");
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>//static double AnnualInterestRate
static class variables are just like global variables with a class scope. They have to be declared at the top of a *.cpp file just as if they were normal global variables.

// account.cpp file
#include "StdAfx.h"
#include "Account.h"

double Account::AnnualInterestRate = 0;
// rest of code goes here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>THe only thing that seperates each sentence would be a new line.
Those are not sentences. Those are just lines, and getline() is what you want to use.

using a vector is the easiest way to do it when you don't know how many lines there are. If you know you only want two lines then just create an array of 2 strings.

There are lots of ways to do your program. I gave you a start and will leave the rest for you to do.

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

If you use std::string and std::ifstream, then you can loop through the file using getline(). Store each string in a std::vector array. The code is very simple, like this: If you only want certain line numbers then just count them inside the loop.

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

int main()
{
    vector<string> array;
    string line;
    ifstream in("filename");
    while( getline(in,line))
    {
           array.push_back(line);
    }
}

>>but I am wanting to be able to have control over each sentence itself.
Do you mean each line? getline() knows nothing about sentences. Is there something unique that separates one sentence from another, such as a blank line?

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

Cody: if you want to post code, that is ok, but please

  • Use code tags [code=c++] /* code goes here */ [/code]
  • Don't use ancient header files with .h extension
  • Don't use eof() as you did in line 12 because it doesn't work like that

>> This reads the text in as characters
Why? it could read into integer variables just as easy. By reading in as strings the strings have to be converted into ints before they can be used. That just extra unnecessary work.

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

Everything compiled ok, that error message just means it could not find the class constructor. Make sure method.cpp is part of the dev-cpp project.

One error is that the project has two main() functions. you need to delete one of them.

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

>>I get a linker error with the above code
What is the error message ?

>>So why cant i declare my Employee employee_list[100] in the main.cpp file?
I thought you said you are getting a link error? link errors will not produce this error, but a compile error will. What is the exact compile error?

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

you mean the code you originally posted in post #1? Well, for starters, numbersuffix is undefined.

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

I made no other changes. Just to make sure, I copied it all over again and just made that one change. I used VC++ 2008 Express. What compiler are you using?

Attached is my project if it will help you.

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

When I comment out lines 138-141 I get an error at line 178 that says "... error C2664: 'CartesianPoint::CartesianPoint(const CartesianPoint &)' : cannot convert parameter 1 from 'double' to 'const CartesianPoint &' ". To me, the initial error is cause by something very simple to be missing. But, I can't see the "tree thru the forest"....Anyone got an eagle's eye as to the cause?

Yup -- the problem has nothing to do with lines 138-142. Read my previous post for the correction to that error. The problem is mismatched parentheses.

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

you need to keep track of the last valid pointer as the loop is iterating through the linked list. Then after the loop terminates reset pWalker to the value of the last known good value. Something like this will probably work.

int Count_Words(word *&pWalker, int &count)
{
    int numWords = 0;
       
    pWalker = letter[count];
    word* pTail = pWalker;    
    while (pWalker != NULL)
    {
        letter[count]->back = pWalker->next;
        pTail = pWalker;
        pWalker = pWalker->next;
        numWords++;
    }
    pWalker = pTail;     
    return numWords;     
}

>>shouldn't walking backwards in a double linked list be just as easy as walking forward
Yes, but you have to start out with the last node in the linked list (or tail) -- NULL is not a valid pointer. Then when iterating backwards you can check for NULL because it need to check for the head of the linked list. So there are some differences in how you have to code it.

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

The problem is elsewhere. I tried to compile with VC++ 2008 Express and got errors on FindPerpBisector(). When I recoded like this everything compiled ok. The problem seems to be mismatched parenthases.

void LineSegment::FindPerpBisector()
{ 
   LineSegment perpBis;
   double x = (first.X() + last.X())/2.0;
   double y = (first.Y() + last.Y())/2.0;
   CartesianPoint midPt(x,y);

<snip>

Another suggestion: you header files and class declarations would look a lot better by actually using inline code in the class instead of writing separate functions using the inline keyword

class CartesianPoint
{
 public:
    CartesianPoint() {myX = 0.0F; myY = 0.0F;}
    CartesianPoint(double xVal, double yVal)
        { myX = xVal;  myY = yVal;}
    double X() const {return myX;}
    double Y() const {return myY;}
   void SetX(double xVal) {myX = xVal;}
   void SetY(double yVal) {myY = yVal;}
 
 private:
   double myX, myY;
 };
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in the code you posted, marray is an array of uninitialized integers, which could have any random values. Consequently the code you posted makes absolutely no sense at all. To add up all the values in the array

int sum = 0;
for(int i = 0; i < numbers; ++i)
    sum += array[i];
cout << "sum = " << sum;
jonathanasdf commented: thanks for your attempt. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 124 looks a bit strange.
CatesianPoint is a class, but you are using it like a typedef?

That line is ok. Class objects are declared like that.

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

The compiler doesn't know how to output the CartesianPoint class. You probably need to write an overload operator >> for it. You didn't post that class so we have no idea how to help you.

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

That's not right. Look at function Display_Results(). pWalker is declared in that function and never set to anything. Its just a pointer that points to some random memory location, unless of course you changed the program since the last post.

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

Which of the 232 lines does that error occur on ?

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

This c++ code also uses FileSystemWatcher

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

As I said, you are passing a NULL pointer for pWalker. Fix that and it might work the way you want it to.

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

you do have to allocate memory, the problem is that you tossed it into the bit bucket by setting it to NULL in the else statement. You should not have commented out the two lines that set the next and previous variables to NULL -- that was correct.

Display_words() -- you do have to test pWalker for NUL because I see where a NULL pointer is being passed to that function (Display_Results()). Just a simple test will do it.

void Display_Words (word *pWalker, int &count)
{
    word *pCurrent;
    if(pWalker != NULL)
    {
        pCurrent = pWalker;
    
        while (pCurrent != letter[count])
        { 
            cout << pCurrent->newWord << " ";
            pCurrent = pCurrent->back;
        }

    }     

}

After making the above corrections I get this output, using the file that you posted

Results for file ..\TextFile1.txt: 6 total words processed.

2 word(s) beginning with 'G':
1 word(s) beginning with 'M':
1 word(s) beginning with 'S':
1 word(s) beginning with 'T':
1 word(s) beginning with 'W':


Press any key to continue . . .

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

I'm starting to step through you program now. So far it is full of memory leaks. First place I see is in the function Initialize_Linked_Lists(). First you allocate a word object then turn around and set the pointer to NULL and return a NULL pointer. Huge mistake.

Correct_Word(). When you erase a letter out of the word you have to adjust variable len in the loop because you changed the length of the string. Also reset count to -1 so that it starts that loop all over again.

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

I get a compile error with VC++ 2008 Express because you didn't include <algorithm> to define transform.

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

word * pCurrent = pWalker; -- just don't use the new operator like you did on line 516.