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

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

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

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

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

>>.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

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

http://www.youtube.com/watch?v=LCAdotyM-Eo

Warning: contains GF violence.

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

>>return *(--s1) - *(--s2);
That may give you the wrong result. It should be return *s1 - *s2; There are four possible return values

  1. If *s1 is '\0' and *s2 is not, then the return value will be some negative value.
  2. If *s1 is NOT '\0' but s2 is, then the return value will be some positive value
  3. If both *s1 and *s2 are '\0' then the return result will be 0.
  4. If neither *s1 nor *s2 is '\0' then the return value could be either positive or negative, depending on their values.

In either event, decrementing s1 and s2 before the subtraction may (and most probably will) produce the wrong result because s1 and s2 will not be pointer to the characters that cause the previous loop to terminate.

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

Adding the "." to your path is not a desirable way to fix the problem. It may work for you, but not for anyone else that tries to run your program.


>>How can I prevent the exec call from running other programs (located in the same directory)...Any ideas?
It won't. It only runs the program that's named in the first argument to that function.

Salem commented: Very true +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 14 of CMain.h -- global objects can not be declared in header files because the compiler will try to create them in each *.cpp file in which the header file is included. Instead, use the extern keyword in the header file then in one, and only one *.cpp file declare the object without the extern keyword.

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

Has my opinion changed? No. They're still all just a bunch of crooks and thugs. Do I regret voting for Obama? Yes, but I probably would have regretted voting for McCain too. Unfortunately, the recession changed all the rules for everyone. No one can foretell the future, so Obama and Bush tried to buy our way out of that situation. Whether it worked or not will probably not be known for several (or many) years.

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

It will not work with Turbo C because that compiler can not call any of the ms-windows library functions. As for borland, it depends on which version you are using. If its a 16-bit version like Turbo C, then that compiler will not work either.

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

I realize I'm a little late in this thread. RGB() in windows.h is just a #define and as such you do not need to use any of windows libraries. Just put this in your program. #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) A COLORREF is nothing more than typedef unsigned long COLORREF; So, you could do something like

switch(RGB(20,30,40) )
{
    case RGB(20,30,40):
}
josolanes commented: I appreciate all your help!! Will try it with COLORREF +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

switches with multiple variables is no supported, just as you thought it might not be. But ... if you convert the rgb values into COLORREF value then you could use that in the switch statement.

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

>>Need an answer

The answer is to use google.

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

Here is the correction to that insert function. Note that neither of the two loops you had work. In order to expand the array you have to start from the end of the array and work forward, decrementing the loop counter along the way.

Also you need to add some code that verifies that you don't attempt to insert more names then the array can hold. You have hardcoded the array size as 30, so you need to produce an error message if you attempt to insert a 31st name. There are better ways to do it so that you can enter as many names as you wish. One way is to allocate the number of pointers so that they can be expended when and if needed. Another way is to use a linked list, but you may or may not know that yet. A third way is to use either c++ <vector> or <list> class, but you many not know that yet either.

void doInsert(Listtype &list)
	//precondition: list has only the list from file data.txt
	//postcondtion: list is filled with user data and appended by adding a new list at a position specified by user
{
	system("cls");
	
	char firstname[30];
	char lastname[30];
	int age=0;
	int	pos=0;

	
	cout<<"input first\n";
	cin>>firstname;
	cout<<"last\n";
	cin>>lastname;
	cout<<"age\n";
	cin>>age;
	cout<<"pos\n";
	cin>>pos;
	list.size++;
	
	
    for(int i = list.size; i > pos; i-- )
	{
		
		list.person[i]=list.person[i-1];
		
	}	

	list.person[pos]=new Listnode;
	strcpy(list.person[pos]->firstname,firstname);
	strcpy(list.person[pos]->lastname,lastname);
	list.person[pos]->age=age;
	
		
	cin.ignore();
	cin.ignore();

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

I thought this website was for helping people I have not gotten a single help. I have been going over and over on this code and no help

It is for helping you. I just got home from work is why I have not tried to help you more.

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

what version of vs are you using? I tried to compile that *.cpp file using VC++ 2008 Express and get lots of errors. There have been lots of changes between vc++ 6.0 and 2008, so you might want to compile it with 2008.

Also, please post randomc.h

lukebradford commented: Thanks for the help! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No. But you could open a socket to another computer and ask it what time it is. Read this link

Salem commented: Nice +19
jonsca commented: What if the other PC isn't wearing a watch? +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Yes, do the same thing for date. There is another way to write that function to avoid the static declaration of the buffer.

const char* gettime(char *inputbuf)
{
   // other code here
    return inputbuf;
}

You could also use strftime() but I never use that function because doing it myself is just as easy.

Look at struct tm in time.h and you will see the names of the date and time members.

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

you mean something like this:

const char* gettime()
{
    static char curtime[20];
    time_t now = time(0);
    struct tm* tm = localtime(&now);
    sprintf(curtime,"%02d:%02d:%02d",
          tm->tm_hour, tm->tm_min, tm->tm_sec);
    return curtime;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The first TV I bought that had a remote control I could change channels by jingling my car keys.

I also remember TVs that had round screens, and pictures were only in black & white. Then when color was becoming popular each program shown in color would be advertised as "Brought to you in living color!" and a peacock tail feathers.

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

No, I do not create movies.

You mean "yes" I do not create movies. When you say "no I do not", that means you do -- two negatives make a positive :)

"Yes, we have no banannas .."

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

My dream computer would be a hologram that computes in the future and returns the results to the present, like in Star Trek Next Generation.

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

>>what program will use with to problems....

That doesn't make a lick of sense. I hope English is a second language for you. If English is your mother tongue then you need to go back to grade school and learn how to write a proper sentence.

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

lines 5 and 7 are do-nothing lines. The don't do a damned thing. You could delete both lines and the loop would work the same way.

>>//resets command to null
Says who???

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

I am using char * for getting data from the user. Now, if i just do

char * data = new char[100];
cin >> data;

The data is corrupted, i.e. only data before whitespace is stored; and the following is an example result:

enter: "Microsoft Co."
data: "Microsoft"

Can someone tell me why this thing happens?

It has nothing to do with dynamic memory allocation. The >> operator stops at the first white space. If you want text that includes spaces then you need to use getline(). Using std::string is preferred but you can use character arrays too. cin.getline(data, 100);

Also, secondly, I want to avoid declaring a size to the char *, since i want the input to be flexible. Now, the following code says that the 'data' is not initailized when executed:

char * data;
cin >> data;

Any idea how to come around this?

Thanks!

Your compiler is correct, you can not use a pointer before it has been allocated, as in your first example. The solution you are seeking is in std::string. With that class you do not need to specify the string's length, and can be used almost exactly like a character array.

std::string data;
getline(cin, data);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 20: Whether that line succeeds in connecting to your printer will depend on the printer and operating system. I have an HP Officejet laser printer on USB (Windows 7) and that line failes to open it.

line 24: you are sending a binary number to the printer. Printers do not know how to print them. The number will have to be converted to text before sending it to the printer.

char text[20];
sprintf(text,"%d", i);
fputs(text, printer);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>void arrays::Talk(hold&, keep&) {
from line 5. You need to add the data type of each of those parameters, such as void arrays::Talk(string &hold,int &keep) { >>a.Talk(feelings&, array_size&);

Remove the two & symbols.

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

You need to use { and } between the if and else statements

if( something )
{
   // code here
}
else
{
   // more code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>i want to give a presention on functions use in code
>can any one help me ,as give me these codes?
Wait. You're giving a presentation on something that you don't even know how to do?

Is that so uncommon? The idea is for him to learn how to do it so that me can make the presentation. I did that once for a speech class about 30 years ago -- made a presentation about the evils of marijuana. Didn't know a thing about it except what people had told me so I read every available book on the subject. The final presentation was a lot different than the one I thought I was going to make.

The idea of the above is that if you (the op) don't know a thing about the topic then you had better start studying. Just asking other people to give you the information without you yourself understanding the information will result in failure.

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

>>Base * ReturnPtrToANewBaseClassObject()
In base.cpp you forgot to add the Base:: class scope Base * Base::ReturnPtrToANewBaseClassObject()

Carrots commented: Thanks ever so much for your help! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hey i dont understand why do u need to develop such an application when u have this things done already in java???

I don't understand why you are replying to a two-year-old thread?

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

0 seconds is probably correct. Computers will execute that code in just a few nanoseconds. Call clock() instead of time() because clock() has higher resolution. But that too may result in 0. If it does, then call that Multiply function several hundred times and take the average time.

clock_t t1, t2;
for (int i = 0; i < 5; i++)
    {
    t1 = clock();

    for(int k = 0; k < 1000; i++)
        A.Multiply(B);

    t2 = clock();
    dif = t2 - t1;

    cout << "This took "<< dif << " miliseconds" << endl;
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

How would that reduce the problem? Now if there was a fee for each post :) :) :) But that would probably eliminate everything in Geeks' Lounge, except for those members who have too much money.

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

>>I do not understand why jump statements are so frowned upon.
Because it results in spaghetti code which is difficult to read and understand.

>>Anywho, I would prefer to use scanf over getchar.
I didn't say getchar(). I said fgets(). Doesn't matter whether you or I like it or not -- scanf() is a crappy function that does crappy things to the program. Get over it and use functions that actually work.

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

>>I am getting stuck in an infinite loop when I input a character instead of an integer during a scanf("%d"....);

That's why I always (or normally) use fgets() instead of scanf(), then after validating input convert the text to an int.

C language does not provide a standard way to clear the keyboard buffer of all unwanted keys, but fgets() does. If the last character of fgets() is not '\n' then there will be more keys avaiable from stdin.

>>start: // I use this to restart the program
In C language you should use a loop, not jump statements. You could use do loops or for loops to do that. For example

bool done = false;
do
{
    ...
    switch( command )
    {
      ...
      case 11: // quit
      done = true;
      break;
    }
} while( done == false );
jephthah commented: yes +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Your compiler does not support threads. You will have to use a modern compiler such as Code::Blocks or VC++ 2008 Express, both are free for the downloading.

Salem commented: Yes +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When line 2 failes that function should return right away instead of processing the rest of that function.

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

That's why you should write and debug such programs in small sections. I suppose you are using *nix, so learn to use a debugger such as dbg, which will pinpoint the seg fault for you by using the core file. The program first has to be compiled for debug -- I think its the -g option.

Salem commented: Nice +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

if( windspeed >= -40 && windspeed <= 40) When working with negative numbers the operation is the reverse of positive numbers. That is, -50 is less than, not greater than, -40.

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

Memory for all types of static variables is allocated when the program is compiled, just the same as when memory is allocated to normal global variables. When your compiler creates the executable program that program includes memory for all the functions that you wrote (or linked with in libraries) as well as global and static variables. The operating system deals with all that when it loads the program into memory.

In short, memory allocation for the three cases you described are all identical.

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

wrong compiler. Use either Code::Blocks or VC++ 2008 Express (both are free) so that the program can take advantage of up to 2 gig RAM and huge data files. The compiler you want to use can't either of those. You will also learn how to write a modern c++ program and possibly write a gui program instead of a text based program.

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

You should create another thread and put that serial port stuff in it so that it doesn't block the gui main thread. Then when something comes in collect the string(s) and send a windows message to the main gui thread so that it can display the string(s) or do something else with them.

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

I wouldn't make duplicates of A and B, but put the results in matrix C so that A and B are left unchanged.

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

>>Can anyone help please? Thx!

Sure can. See below

int main()
{
   // put your code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't want to continue this discussion here because its hijacking the thread and not relevant to the topic of this thread.