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

>>API should be in the form of static library.

There are two kinds of libraries -- static libraries and import libraries (or dlls). When you create a new win32 project you have a choice of Windows Application, Console Application, DLL or Static Library. Choose the last one.

I suppose they want you to convert your program into a DLL, which uses the static library you already have. How to do that will depend on your application program.

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

Beats me. You are writing the program, not me. Instead of using the struct record I posted, you can easily change your car record to hold char arrays instead of std::string. Then write the array of those classes like I did the structures. You may have to write them out one at a time if you did not make an array of those classes.

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

Sometimes I think even 15% is too much. For example I went to a restaurant and spent $100.00 USD, the 15% tip is $15.00. That's pretty good pay for about 10-15 minutes worth of work for the waiter ($60.00 per hour).

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

The easiest way to create binary files is to use fixed-length character arrays instead of std::string. That will make each of the records in the binary fine the same size and you can easily locate any record in the file by simply multiplying the record number times record size.

struct record
{
    char make[40];
    char model[40];
    char color[20];
    int year;
    int mileage;
};

ofstream out("filename.bin", ios::binary);
struct record r[3];

// write three cars
out.write( (char*)r, sizeof(struct record) * 3);

// read 3 cars
ifstream in("filename.bin", ios::binary);
in.read( (char *)r, sizeof(struct record) * 3);
Salem commented: Level up! +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Do you know how to convert an integer to binary (characters are really integers). If you don't, then google and you will find out how. Once you have a function that does that then you should be able to convert all the characters in a file to binary.

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

strtol() sets the pointer (second parameter) to the first character which it could not convert to int -- e.g. it's the '/' character in the string you enter. The ++ptr just advances that pointer past the '/' character so that is is not set to the first digit of the next part of the string.

The last parameter to strtol() tells it how to interpret the string (base). Base 10 is decimal, base 16 is Hex, base 8 is Octal. I have not tried it but you base 2 will mean the string is in binary 0 and 1s.

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

I usually try to tip 15% -- never 20%, at least not intentionally.

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

If you have the option to use any compiler that you want then download and install either Code::Blocks with MinGW compiler, or Microsoft VC++ 2008 Express.

I already explained what you need to do for item #4.

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

what are the value of those two variables ? what was your input string? use strtol() and you will get better results

char *ptr = 0;
month = strtol(s, &ptr, 10);
day = strtol(++ptr, &ptr, 10);
year = strtol(++ptr, &ptr, 10);

Note that with strtol() the input string may or may not contain leading 0s, such as it will recognize "2/3/10", or "02/03/2010", or any other combination as long as there is one character separating month, day and year.

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

Good notion, but it doesn't work. I input "Now is the time for all good men to come to the aid of their country." and all I got back was "untry". I was expecting to get back the first 20 characters of what I had typed, and your function to toss the rest of the characters into the bit bin.

int main()
{
    char buf[20] = {0};
    int x = getUserInput (buf, sizeof(buf));
    printf("x = %d\n%s\n", x,buf);
}

Now is the time for all good men to come to the aid of their country.
x = 69
untry.
Press any key to continue . . .

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

Thanks.. However, I got the following error when i tried to compile the code.

error C2039: 'Detach' : is not a member of '_bstr_t'

Btw, I'm using VC++ 6.0

You are using an old compiler -- I used VC++ 2008 Express. Look in your compiler's online MSDN and see what methods _bstr_t has.

You can also do it without using _bstr_t at all. Just call SysAllocateString() -- example here.

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

I'll bet you are trying to run that program under MS-Windows version XP or newer? If that is true then you can not run that program on your os. Install Win98 or MS-Dos Version 6.X and try again. I know that's not what you want to hear but that's the breaks when you use an ancient obsolete 16-bit compiler on modern MS-Windows. It's like trying to put a model T engine in a 2010 car -- won't work.

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

what compiler are you using? iostream.h and fstream.h are obsolete. c++ std::string is declared in <string>

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

If your compiler can not compile the above then you are using an obsolete compiler, most likely Turbo C++. I don't know if that compiler even supports std::string class. If not, then you could use character array instead of std::string.

Here is a simple code snippet how to use getline() with character arrays.

ifstream in("filename.txt");
char buf[255];
while( in.getline(buf, sizeof(buf) ) ) // read until end of file
{

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

You can't assign the variant like that because _bstr_t owns the memory.

int main()
{
_bstr_t  a = (L"Joe Schmoe");
_bstr_t b = (L"Accounting");
VARIANT vtEmpName;
VARIANT vtDept;
vtEmpName.vt = VT_BSTR;
vtEmpName.bstrVal = a.Detach();

vtDept.vt = VT_BSTR;
vtDept.bstrVal = b.Detach();
}

you can also do it like this:

int main()
{
VARIANT vtEmpName;
VARIANT vtDept;
vtEmpName.vt = VT_BSTR;
vtEmpName.bstrVal = _bstr_t(L"Joe Schmoe").Detach();

vtDept.vt = VT_BSTR;
vtDept.bstrVal = _bstr_t(L"Accounting").Detach();

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

Aia brought up one of the reasons I recommended strtol() instead of strtok(). With strtol() you can make each of the conversions in one single line of code (one for each variable), and no loops.

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

correction

int mstrcmp(const char *s1, const char *s2)
{
    while((*s1 && *s2) && (*s1 == *s2))
        s1++,s2++;
    return *s1 - *s2;
}
tux4life commented: Yup, now I can fully agree on you :) +8
jephthah commented: i'm glad tux agrees with you. :P +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, bubblesort() still has two more problems

First, the sort algorithm doesn't work right.

for(x = 0; x < i-1; x++)
      for(y = x+1; y < i; y++){
            compares(1); //1 comparsion made
            if(a[x] > a[y]){
                  temp = a[x];
                  a[x] = a[y];
                  a[y] = temp;
                  moves(2);
            }// end of if
      }//end of for

second, the loop is incorrect when displaying the array for(j=0;j<=i;j++){ that should be j < i not j <= i

churni commented: thanks for the help - you really are a genius in my eyes! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 61: the value of variable i has not been initialized. As Aia already mentioned, get rid of the i parameter in the three functions that are called from main() with it. Just declare the variable local to each of those functions.

I see that problem on the very first attempt. I asked it to generate 100 numbers and it said that it generated 101.

[edit]Ok, your program works ok, it's just that you are printing the wrong numnber

printf("%d floats merge sorted in %ld moves using %ld comparisons\n"
		                      ,i+1,moves(0),compares(0));

That i+1 should only be i because the value of i already contains the number of items in the array.
[/edit]

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

you can use strtol() which avoids at least one of the problems with strtok().

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

you will have to post the entire program because there is no way anyone can determine the problem from the little code you posted.

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

what line number (from the code you posted) ? And post the exact error message.

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

post current code

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

why didn't you read your other thread?

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

what do you mean you want to convert it to binary? Like the letter A (which has a decimal value of 65) = 1000001?

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

while loop is incorrect. You need to read all the records, not just the first one for that doctor. BTW writing short programs to solve a specific problem save you a lot of time.

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


struct doctor
{
    char name[80];
    char regis[80];
    char pname[80];
    char treatment[80];
    char piont[80];
    int fees;
    int collect;
    int insure;
    int balance;
};

int ReadLine(FILE* customer1, struct doctor* det)
{
    return fscanf(customer1,"%s %s %s %s %s %d %d %d %d",
        det->name,det->regis,det->pname,det->treatment,
        det->piont,&det->fees,&det->collect,&det->insure,&det->balance);   
    
}

int main()
{
   struct doctor det;
   int Found = 0;
   int count = 0;
   int fees = 0;
   int collected = 0;
   
   char doctor1[] = "Dr.Robert.Williams";
    
    FILE* customer = fopen("textFile1.txt", "r");
                                         
    while( ReadLine(customer, &det) > 0)
    {
                                                
        if(strcmp(doctor1,det.name)==0)
        {
            count++;
            fees += det.fees + fees;
            collected += det.collect; 
        }                                            
    }                                            
                                                 
    printf("\n\t\t  DOCTORS NAME:%s",doctor1); 
    printf("\n\t\t  NUMBER OF PATIENTS:%d",count);
    printf("\n\t\t  TREATMENT:%s",det.treatment);
    printf("\n\t\t  TOTAL FEE CHARGED:$ %d",fees);
    printf("\n\t\t  AMOUNT PAID:$ %d",det.collect);
    printf("\n\t\t  FEES COLLECTED:$ %d",collected); 
                                        
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there a way to fix this?

Probably. My guess is that the program is not using the right brush color for painting. There are lots of ways to do that but the simplest might be to make the brush a global object so that it doesn't get destroyed between paint function calls.

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

Read the file by line, not by character because you will need to parse the words in the file in order to find key words. So read the file using getline() instead of get().

To do #4 you will have to make an array of key c++ words. The easiest way to do that is probably with google. I have seen several sites that list c++ keywords, so you can just copy/paste it into your program then make an array of strings out of them.

Next, check each line read with getline() to see if it contains any of the keywords. If it does, then increment the keyword counter. But make sure it really is a keyword and not a variable name that just happens to have a keyword embedded in the name.

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

Do not put executable code such as lines 27-30 in header files. If you want to make that inline then put it in the class declaration the way you did getName(). You have several functions mis-coded like that.

class GrandParent
{
public:
	//constructor
	GrandParent(string name) {_name = name;}

	//Getter
	string getName() const { return _name; }

private:

protected:

	string _name;
};
Carrots commented: Thanks for trying to help me! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yup -- previous errors confirmed when I tried to compile it with Code::Blocks. Will not compile at all with VC++ 2008 Express because it does not support dir.h

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

On my Code::Blocks, F9 toggles a breakpoint. But to compile/link and run the program, you probably want to use F12. See the Code::Blocks' Build menu.

You may have an old version of the IDE. I have 8.02 and F9 is "build and run"

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

You have to be careful of lines like this: while(myStack->data[top]!='(')

top is not a variable, but a member of the STACK structure. So you need to write it like this: myStack->top. You have that same error several times.

>>push(&myStack, symbol);
variable myStack is already a pointer, so remove the & address operator.

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

use c++ fstream class. google and you will find several tutorials.

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

Did you create a console project? e.g. File --> new --> project then select Console Application in the popup box.

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

You're going to have to provide a whole lot more information about your robot if you really expect anyone to help you. You made it sound like you have a robot walking down our city streets!

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

I however always did get a laugh when I went to Microsoft for some tutorial or sample code on something, then found out that what their tutorial was teaching was wrong or that their sample code did not work. Microsoft products are a joke.

Yes, their documentation was notoriously horrible in past years (10+ years), but they've cleaned it up quite a bit since then.

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

IDE STANDS FOR Integrated design environment. it is something similar to WYSIWYG editors.

THE Differences between tc++ and visual c++ is diffference in the header files,otherwise the syntax is same.

and libraries and DLLs -- tc++ doesn't use dll's.

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

post the whole program. In the code you posted the variable hydraulicRadius was not defined. Did you include <math.h> ?

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

The best approach is to use standard c++ file i/o classes and methods because that gives your program the best portability should you decide to port it to another operating system sometime in the future. Using win32 api file i/o functions is a little like limiting yourself to only binary reads/writes because they know nothing at all about text files.

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

I might have been mistaken about that. Using google I found this news item

Britain revokes U.S. independence
Catholic New Times, Jan 16, 2005

In a shocking move, the British House of Lords recently revoked American independence: the U.S. says it will appeal to the International Criminal Court, if and when it recognizes it. The following is a letter from the British House.

To the citizens of the United States of America,

In the light of your failure to elect a suitable President of the U.S. and thus to govern yourselves, we hereby give notice of the revocation of your independence, effective today. Her Sovereign Majesty Queen Elizabeth II will resume monarchical duties over all states, commonwealths and other territories, except Utah, which she does not fancy.

Your new prime minister, The Right Honourable Tony Blair, MP will appoint a Minister for America without the need for further elections. Congress and the Senate will be disbanded. A questionnaire will be circulated next year to determine whether any of you noticed. To aid in the transition to a British Crown Dependency, the following rules are introduced with immediate effect:

1. You should look up "revocation" in the Oxford English Dictionary. Then look up "aluminium." Check the pronunciation guide. You will be amazed at just how wrongly you have been pronouncing it. The letter 'U' will be reinstated in words such as 'favour' and 'neighbour,' skipping the letter 'U' is nothing more than laziness on your part.

2. There …

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

When ~S.O.S~ called everyone Mr. <UserName Here> That drove us all crazy, and he eventually dropped the Mr.. :)

Nick Evan commented: I remember that :D +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The code you posted has nothing to do with the problem. Try posting again but this time make sure you post the correct program.

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

>>.what can i do

replace the current version of MS_Windows with MS-DOS 6.X or Win95.

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

Huh???

Link

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

Don't know about vetoing laws, but she can dissolve parliament and schedule a new election. Office of the PM evolved before USA had its tea party and tossed the Brits out of our country. BTW it was Queen Elizabeth II who formally declared the USA an independent country. I don't recall when it was but I do remember seeing it on tv.

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

Read it one character at a time, then if it's not a space add it to a character array.

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

line 75: while((clock ()/CLOCKS_PER_SEC)<(hours*3600)){

That is the problem (or majority of the problem). That line is not allowing any other process to run and just hogs up all the cpu time. Depending on the operating system put either Sleep() or sleep() to allow other processes to run.

A few other tweaks might improve speed a few clock ticks. For example
lines 87 and 88: you don't need that loop. memset(listings, '\0', MAX_LISTINGS * MAX_CHARS_PER_LINE ); lines 67-73 can be deleted. Just initialize the array where it's declared.

char *keywords[] = {
   "E. ORLANDO", "E ORLANDO", "EAST ORLANDO", < etc > 
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Why don't you use the standard C function fgets()? Or are you not allowed to do that?

char name[10];
fgets(name, sizeof(name), stdin);
if( name[strlen(name)-1] == '\n')
   name[strlen(name)-1] = '\0';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I think the problem is since its a double (64 bits) and can only send 32 bits.

A pointer is not 64-bits unless you are compiling with a 64-bit compiler. All pointers, regardless of type, are 32-bits when compiling with a 32-bit compiler. So your concern that a double pointer is 64 bits is unfounded -- that is not the problem.

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

lines 56-60 are unnecessary. Just use the std::string version. No need to convert to char*.

line 61: Why declare those as doubles? missing, correct, and wrong will never have decimals, so you might as well declare them as int (or long if you want). Typecast them to double when using them in division algorithms.