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

I think a lot of people are interested in updates!

Name one.

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

What compiler are you using? Learn to use your compiler's debugger so that you can step through the program and find out for yourself what is causing the problem.

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

The smallest unit of storage in a computer is one byte. What you want to do is to bitmap the byte(s) of memory, one byte normally holds 8 bits (but may vary depending on the operating system). So if you want an 8x8 matrix of bit then use an array of 8 unsigned char, e.g. unsigned char bits[8], then you can use shift operator and/or the & and | operators to set/clear specific bits.

Another way to do it is to define a structure that contains the bits

struct bits
{
   unsigned char b1:1; // bit 0
   unsigned char b2:2; // bit 1
   // etc for 8 bits
 }

 struct bits bitArray[8];

With the above structure you can set/clear bits by using the bit name instead of shifting. Example: bitArray[0].b1 = 1; // set bit 0

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

The problem you see is that c++ stream library may or may not be thread safe meaning that you might see almost any random output or a mixture of the two. Read this thread for more information.

If you want specific output then you will have to add thread synchronization techniques, such as creating and using a mutex. Here are a few google links you might want to read.

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

I've never seen Dirent.h or any of those includes before.

You will see them a lot when you do *nix programming. Just like you see windows.h when doing Ms-Windows programming. C is the standard implementation of os interface functions because almost all other languages can call them. c++ functions can only be called by c++.

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

The first thing you need to do is split up the Hotel class into three different classes

  1. GuestInfo
  2. RoomInfo
  3. Hotel

class Hotel should contain an array or vector of RoomInfo classes

class RoomInfo should contain an array or vector of GuestInfo classes, as well as the room number and other objects related to the room. When you need to change the room number all you have to do is locate the instance of RoomInfo from the array/vector in Hotel that has the same room number as the current room number, then simply change the room number in that RoomInfo instance. Of course when you enter the new room number you need to verify that the new room number isn't already taken.

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

int raw_len = sizeof(MyTest_u_char2) + 1;

That line is wrong -- sizeof takes the size of a pointer, not the number of bytes allocated to the pointer. In this case sizeof(any pointer) is 4 (in most implementations today but could be some other value depending on your compiler). What you want is the const 8. Better to declare a const int for that and use it throughout so that you don't have to repeat magic numbers all over your program.

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

There are several higher-level c++ alternatives, such as C#, Windows Forms (which is CLI/C++), MFC, wxWindows, QT (cross-platform) just to mention a few. C#, WF, and MFC you will want to use Microsoft's VC++ 20?? compiler/IDE.

sss93 commented: Thanks I know but I would prefer learning more of the lower level aspects and making it work to my needs , Ive looked at c# and it seems much simpler and less tedious....however I more interested in accomplishing my goals in C++ +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

wishes grated. But ...
1. You landed on mars and burned to death
2. you are instantly teleported back 5 billion years long before there people or planets, and no other way to get back home.
3. I stole one for you and now you are in possession of a hot bike, and you get 10 years prison for possession of stolen bike.

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

If the OP is from India he may not have any other choice but to use Turbo C/C++ because sadly that's what is taught in their universities.

SoreComet commented: agreed +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

wprinf() and related functions work with unicode characters. You may have to change the code page in order for other languages to display correctly.

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

The first problem is the program is attempting to change data that is stored in read-only memory. String literals can't be changed. You can correct that by storing the string in read-write memory like this:

char data[]="ALOK KUMAR   ASHISH KUMAR   ANKUSH

After that you will want to set pointer t = data.

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

you need a semicolon ; at the end of the class declaration in the header files. Also, in the *.cpp files, remove the semicolon before using namespace std statement

class foo
{

   // stuff here

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

Hunger Games -- a chick flick, pretty slow at first but action picks up about half way through. If I ignore the first half of the movie I'd give it 3 out of 4 stars, but overall it only gets 2 stars.

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

Want to die with a smile on your face?? Have sex with 100 vergins all at the same time :)

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

please make this thread as "must read"

There is only one MUST READ thread and that's the DaniWeb Rules. All others are optional just as this one should be.

Just share that what have you all done in your universities/scholl time which made you to come to this level of programming

Nothing out of the ordinary at the university. Programmers become competent and proficient by on-the-job experience, and lots of it. And they don't become proficient in every part of programming because the field is just too broad. Same idea as a medical Doctor who specializes on one part of medicine. If you want to be a jack of all trades you will not be proficient in any one. In college you just hit the highlights of programming, you don't really start learning the trade until you graduate and start working.

You will also want to study other fields of interest while in college because programming is not done in a vacuum but in conjunction with some other field. For example if you are interested in Banking you will find thousands of programmers there who also know a lot about banking.

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

// using the time from ^ above, convert
// secs to HH:MM:SS format using division
// and modulus

Or, just simply call localtime() or gmtime(), which will put it in a structure for you.

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

for (int i =1; i <= 7; ++i)

Line 49: that is incorrect. All arrays start at 0, not 1, and go up to, but not including the number of elements in the array. So that line should be like this:
for(int i = 0; i < 7; ++i)

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

The first one. macros are evil creatures. The macro is wrong anyway. should be like this: #define mult(x,y)(x)*(y)

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

You can easily do it yourself. Just look up those hex numbers in any ascii chart

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

The results make sense -- vectors have a lot of overhead that take cpu cycles, more time than just doing the calculations. The program has to make other calculations just to access the vector item.

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

Sorry, but killing someone is never funny or humorous, except maybe in a cartoon like RoadRunner where the person or other living creature is not really killed.

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

Xor all the numbers as you input them. at the end you will left with the number occurs once.

Can you elaborate on that? A couple examples please?

I_m_rude commented: first time, god of C asking a question :D +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I call mktime(). One crevet -- you need to initialize all fields of struct tm to 0 before using it becuse mktime() will return an error of any of the fields contain random junk values. Here's an easy/quick way to do that.

struct tm tm;
memset(&tm,0,sizeof(struct tm));
WaltP commented: A crucible or melting pot? Or did you mean caveat? ;o) +14
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

VC++ defaults to using precompiled headers, which means that it will preprocess all the header files once and use that preprocessed file for all the *.cpp files in the project. stdafx.h is the header file which contains all the other include files that are usd for this purpose. So the first thing that must appear in all *.cpp files of the project is stdafx.h. If a *.cpp file need other includes they must appear after stdafx.h. This might seem a little complicated, but for large projects it can greatly speed up compiling all those *.cpp files. You have the option to turn off precompiled header files if you want to either when you create the project or later by changing one of the project properties. Once you turn precompiled headers off you can delete and remove from the project stdafx.h and stdafx.cpp if you want to.

_tmain and TCHAR are actually macros which allow your program to be easily compiled for UNICODE or not. VC++ defaults to UNICODE, which affects all the strings in the program. You can turn that off in one of the project properties. UNICODE is a computer standard way to represent languages whose alphabet requires multiple bytes of memory. For example each letter of the English alphabet consumes one byte of memory, but in Chinese a letter might need several bytes because they are graphic characters. If you want your program to be in Engligh only (or one of the other western languages) then …

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

go to a command prompt and try that command. BTW your program works ok on Windows 7 using vc++ 2012. What compiler and operating system are you using?

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

It will probably find little green people with long antennas saying "nano nano"

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

line 18: should be text[i] != ' '. You used the wrong loop counter.

After line 23 you should advance i counter until text[i] != space so that there can be more than one space between words

line 15: gets() is a bad function to use becuse it will allow you to type more characters then the buffer can hold, causing your program to crash. Instead of gets() use fgets() so that input length of limited to no more than buffer size. fgets(text, sizeof(text), stdin);

tmp->word[m]=*(y+m);

lines 34-38: Too compilicated. Just call strcpy() which doesn't need as loop. Unless of course if you are not allowed to use strcpy()

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

when I run it I get this assertion error

TRUECONTENTS OF VAL2: 1000000
LENGTH 2
Location: 1001
Location: 250
ELEMENTS: 1 ELEMENTS: 2 ELEMENTS: 3 Starting test one
Location: 1
Location: 500
ELEMENTS: 1 ELEMENTS: 2 ELEMENTS: 3 Assertion failed: i*i < 5 || hm_count(h,
== 2, file c:\dvlp\test1\test1\main.c, line 29

gwolf1 commented: Thanks! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I meant something like this. Next question is how is the file formatted? Post a couple examples of the lines.

    count = 0;
    while(getline(filePath,line)) {
        bookTitle[count] = line;
        count++;
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

lines 86 and 89 are the problem. You need to use a counter that counts the number of times getline() is called so that you can put the data in the appropriate item of the arrzy. Start the counter at 0 and increment it at the end of that read loop.

Ditto for lines 108 and 110

I see you already have a variable named count -- just use that, don't forget to reset it back to 0 before each of those two loops.

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

char command[] is just a simple array of characters, or a single string such as "Hello". You can't store multiple strings all at the same time in it.

char* command[] is an array of pointers to strings, which is what you need for your program. Another way to express it is char** command.

All older compiler require a constant integer to expres the number of elments in array, such as char* command[20]. The newest C standard also allows it to be a variable, such as char* command[argv]. You might have to test it to find out which form your compiler supports. Which ever way your compiler accepts you have to be consistent throught the program, don't use char** command in one place then char* command[] in another because the compiler will complain about that too.

If you are still confused about pointers then maybe you should study this tutorial.

piero.costa commented: perfect awnser! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

while (player[0] == ' ' || player[0] == ' ')

There is no such character as ' ' (four spaces between ticks), that is three or four characters, not one, and must be surrounded in double quotes, such as " ". Even that is wrong becsuse player[0] is a single character.

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

wish granted: Your boss rejected your proposal.....hahaha

LOL I don't have a boss :)

Wish granted -- you are now only live in comic books.

I wish I were an Olymbic swimming champion with 50 gold metals.

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

A 23 year-old man severly burned himself after igniting a firecracker in his butt cheeks (link).

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

void main()

main() ALWAYS returns an int, declaring it as void could result in undefined behavor, read this thread

lines 16 and 17. Most C compilers and C standard before C99 require all variable declarations at the very beginning of a function or other scoped block marked with { and }. To be compatible with C standards older than C99 you should declare them at the beginning of a block. This may be important if your instructor wants to compile your program and does not use the same compiler that you use.

memory allocations: instead of expanding the string buffer one byte at a time it is much more efficient to allocate the memory in larger blocks, allocating too much memory is ok because the incased efficiency offsets the wasted memory. Computers have so much RAM now days that it's not even worth the effort to allocate exact amounts of ram. Here is one way to do it

void foo()
{
   const int BLOCKSIZE = 16;
   char *string = NULL;
   int input;
   int current_size = 0;
   int index = 0;
   while( (input = getch()) != EOF )
   {
       // check if we need to increase the length of the string
       if( (index+1) >= current_size)
       {
           current_size += BLOCKSIZE;
           string = realloc(string,current_size);
       }
       string[index++] = input;
    }
}
teachMyself commented: Helped a lot. +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

wish granted -- you get a computer with no motherboard, CPU, memory or hard drive.

I wish to go on vacation to Australia.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. The array must be in sorted order, you can either enter the numbers that way or call some sort of sort function after input.

  2. Binary search assumes unique values, not duplicate values. The array can contain duplicates but binary search algorithm will find only one of them.

  3. Once one of the values are found the program needs to check other locations immediately before and after the location that was found. Sequential seareches are useful here because binary search can't do that.

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

ave a problem in which i want to declare two pointers of undefined length....so i don't want to use malloc...

you have to use malloc() to allocate space in which to store the characters received from scanf(). If you don't want to use malloc then you have to declare the array as normal, such as char a[20]. However you want to do it the pointer you send to scanf() must point to valid memory large enough to hold all the characters you want to type at the keyboard. A better solution is to call fgets() so that you can limit keyboard input to a specific size.

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

It's hard for everyone.

geojia commented: I wish c++ was the official American lingo +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

there is death for all traitors as far as i know in every country.

US has death penalty for treason, but its rarely enforced. Most were sent to prison, some pardoned by the US President.

the United States Code at 18 U.S.C. § 2381 states "whoever, owing allegiance to the United States, levies war against them or adheres to their enemies, giving them aid and comfort within the United States or elsewhere, is guilty of treason and shall suffer death, or shall be imprisoned not less than five years and fined under this title but not less than $10,000; and shall be incapable of holding any office under the United States."

Here is a list (very short) of persons convicted for treason in USA.

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

Two problems with that code
1. theData in Data() is just a local variable, so line 12 us useless, does nothing.
2. arrays declared inside function can not be returned from the function, attempting to do so will cause sig faults, as you have found out.

To correct the problem, move line 9 to line 17 so that it is declared inside main() instead of Data, then pass it as the parameter to Data(). You will also have to pass the size of the array as another argument to Data() because sizeof does not return the size of an array when used with a pointer.

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

You don't need c++ at all to learn GUI -- afterall, it was originally written in C, not c++. As long as you have basic understanding of c++ you should be fine with QT. Anything you don't know now you can easily pick up while working with QT.

note : sry for the bad english

Please stop saying that. There is nothing wrong with your English.

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

function pointers can only point to static class methods or global c-style functions. You will have to make PrintIt() a static method if you want to do that.

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

can anyone explain ...at what time memory is allocated for variables...

Intel based computers -- All local variables are actually allocated by the compiler immediately upon function entry, even the variables that are declared later within the function. (You will see this if you let your compiler produce an assembly language version of your program) The compiler will rearrange variable declarations so that they appear as if you had declared them all at the beginning of the function. Memory for these is released as soon as the function returns to its caller.

Memory for global variables are always allocated at compile-time and stored in a data segment that is completely separate from code segments. Memory for these are not released until the program itself is terminated.

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

Visual C++ used to have support for makefiles

It still does -- Visual Studio 2012 RC

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

hey..m a student of last year of BCA

Please STOP posting as though you were texting on your cellphone. This is a forum, not a cellphone. If you expect people to take you seriously then you need to spell out the words. There are lots of people here who do not know Engligh well enough to understand what you wrote.

sfuo commented: Engligh! +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

move lines 9 and 43 down into main() then pass the file2 to print() as a parameter. Open the file only once, just before the loop that starts on line 69. Also, fstream objects must be passed to other functions by reference.

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

Several ways to do that, all of them require basic understanding of C and/or C++. If you are using VC++ 2010 Express or newer you can create Windows Forms which is based on the language CLR/C++, similar but different than standard c++.

If you use Code::Blocks then you can use one of their windows packages, but I've not used them.

Or you can do it the hardest way and code in pure win32 api functions. No c++ needed for these, all are C function calls and most MS-Windows compilers support them. This will require six months to a year learning it well.

Regardless of which you choose, that project is probably not something you could complete in a timely manner for school projects unless you have lots and lots of time to devote to study, experimenting and debugging the code.

Best way to get started is at amazon.com -- buy a book or two on the GUI system you choose.

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

As for int 3, forget it.

Yes, because the operating system won't let your program execute interrupts. The processors on Intel based computers do not allow normal programs to use int instructions.

Here is more info about int 3 if you are really interested.