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

hi....... i want a program in c based on any data structures with de code.plz............it shd be catchy n can be based on reality

And you should learn how to write proper English instead of that baby googoo gaagaa talk. That's what's wrong with kids these days -- cell phones and texting have destroyed their ability to write.

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

You still failed to declare those two arrays as I showed you. Also problems in Change() function. main() returns an int, not void.

int main()

{

    char str[20]= {0};
    char enc[20] = {0}; 
printf("enter a string...");

gets_s(str);
Change(str, enc);
printf("%s",enc);


}




void Change(char *source, char *dest)
{

char *s;
char *d;
int i;
d=dest;
s=source;


for (i=0;source[i];i++)  
{
if(RLE (dest, source[i])==0) 
{
*d=source[i]; 
*(++d)=(RLE(source, source[i]))+'0'; 
d++;
}
}
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Plants plant1();

When declaring an object do not include the (). Its just Plants plant1;

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

Yes of course its possible. How to do it will depend on the file's format. Not all images are equal. Here are some links for you to research.

Salem commented: Well said, and nice link ;) +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You will want to use a two-dimensional array for that -- the first dimension is the distance and the second dimension indicates whether there is a car in that spot or not. So you will want to declare the array something like this:

const int MaxParkingSpaces = 10;
int ParkingSpaces[MaxParkingSpaces][2] = {0};

Next you will need to fill the first dimension with the distances you want.

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

You might have to make a few minor changes to your program, depending on how you coded it. For example

for(int i = 0; i < something; i++)
   cout << "Hello\n";
if( i > 10)
   // blabla

VC++ 6.0 will allow the above code but c++ standards and VC++ 2008 will not because of scoping rules for integers declared inside the for statement.

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

See functions in time.h -- particularly mktime() and structure time_t. Also it's not called "forcasting time" -- that is not forcasting anything. Its just simply advancing to some future date.

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

name_t on line 16 overrides the name_t typedef on line 10. Bad idea.

line 15 could be declared as simply char space = ' '; . No need for the array syntax.

I fail to see why you need first_name to be a two dimensional array of 255 characters each dimension! That's enough for 255 names each name 255 characters long. The world's longest name is only 13 words.

BTW the longest name in the world is "Captain Fantastic Faster Than Superman Spiderman Batman Wolverine Hulk And The Flash Combined. "

According to 1978 Book of World Records the longest sir name was 590 characters.

jonsca commented: Awesome trivia! +2
xavier666 commented: The trivia is what hooked me. Lol +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Those are only a few of the millions of problems I see in your program. Well, millions is a bit of exaggeration :)

Other tips:
use int main not void main. main() always returns an int whether you code it to return one or not.

replace gets() with fgets() because gets() will allow you to enter more characters than the input buffer can hold.

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

You can not do it with the Express version because it does not support MFC. Other versions have a wizzard that does it for you.

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

1) provide the full path to the desired destination file

2) system() function, or CreateProcess() win32 api function. There are a few other ways too.

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

Sorry but that is not a quine program (see this link).

A quine takes no input. Allowing input would permit the source code to be fed to the program via the keyboard, opening the source file of the program, and similar mechanisms.

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

The only thing about VC++ 2008 that I do not like (same with version 6.0) is those blasted docking windows. Every once in awhile I accidently undock a window and have a real hard time putting it back into position.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
adnan.siddique commented: you r the best sir +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't want that ancient compiler that is nearly as old as I am :) Get VC++ 2008 Express because its free and currently easily available for download at Microsoft. Just google for it.

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

Happy Holidays everyone :) Wish I could be there to help celebrate. Instead, I'll just drink a beer for you.

~s.o.s~ commented: Cheers! ;-) +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

maybe you want npc.erase(iter); When you do that I have found that you need to start the loop all over again because the value of iter is invalidated.

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

just as you did with structure menber int ident you have to create an object of type NPC_det

struct NPC
{
	string name;
	int ident;
	struct NPC_det
	{
		int health;
		int attack;
		int def;
	} det;//end 2nd struct
}//end 1st struct
int main()
{
    NPC n;
    n.det.health = 1;
}
Suicidal_tool commented: Thanks for the quick reply! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

First step is to just write a program that asks you to enter a value, then use cin to get the value from the keyboard. Once you have that going (compiled without error and runs correctly) you can add the other stuff to it, whic to write a function that contains that formula and returns the result. The function needs one parameter -- the value of x.

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

Drop the course and take C++ Programming 101 course.

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

Hi Mr.Ancient Dragon,
I want seriously give you some thing.. read my private message!
And that its nothing if we compare it with your help :)

As I said in my PM to you, I do not accept payment for any problems I solve here at DaniWeb. But thank you anyway.

Aia commented: Here's some payment in proper currency +8
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Start here. But don't expect you will be productive for a few years.

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

Code below should at least partially solve the problem. There are several ways in which a UNICODE file can be encoded, and the first 2 to 4 bytes of the file will describe which kind of unicode encoding it is. Winipedia has a good article that describes all of them. The code below only implements the UTF-8 encoding, which is really just standard ascii characters. You will have to write the others if you want to implement them.

Unlike my previous attempt this version works ok then the file is opened in text mode.

Note that you will not see "Yes" printed on the screen because the file does not contain any blank lines.

As it turns out, the file you posted does contain the BOM but is otherwise just a normal ascii text file, which is the definition of UTF-8.

void ReadUTF8(FILE* fp)
{
    unsigned char iobuf[255] = {0};
    while( fgets((char*)iobuf, sizeof(iobuf), fp) )
    {
            size_t len = strlen((char *)iobuf);
            if(len > 1 &&  iobuf[len-1] == '\n')
                iobuf[len-1] = 0;
            len = strlen((char *)iobuf);
            printf("(%d) \"%s\"  ", len, iobuf);
            if( iobuf[0] == '\n' )
                printf("Yes\n");
            else
                printf("No\n");
    }
}

void ReadUTF16BE(FILE* fp)
{
}

void ReadUTF16LE(FILE* fp)
{
}

int main()
{
    FILE* fp = fopen("c:\\dvlp\\test_utf8.txt", "r");
    if( fp != NULL)
    {
        // see http://en.wikipedia.org/wiki/Byte-order_mark for explaination of the BOM
        // encoding
        unsigned char b[3] = {0};
        fread(b,1,2, fp);
        if( b[0] == 0xEF && b[1] == 0xBB)
        {
            fread(b,1,1,fp); // 0xBF …
Nick Evan commented: Excellent posts in this thread! +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hi is there any way by which we can write a program that displays its own source code???????:?::-/

Of course, just open the *.c file, read each line and print it on the screen.

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

The idea for this came from another thread in the C++ forum that wanted to duplicate the _getdelim() function that is supported by GNU compilers g++. I made one major change in that this version does not allocate new memory every time it is called, which is grossly inefficient. Instead, this function only allocates new memory if the pointer to pointer passed to _getdelim() is NULL. If not NULL then it assumes the calling program has allocated the memory. The function might expand the size of the line buffer if the number of characters read exceeds the length of the line buffer.

I also removed the goto statements that are in the original GNU function and the ancient K&R style function parameter declarations.

This code snippet uses only standard C functions -- nothing compiler-specific, so it most likely will compile with any 32-bit or 64-bit compiler.

jonsca commented: Nice! +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>CRectangle * d = new CRectangle[2];

That is just allocating an array of 2 CRectangle objects. It could have been written like then: CRectangle d[2]; . But if it did that then it could not replace the 2 with something else at runtime.

>>d -> set_values(5,6);
That is the same thing as d[0].set_values(5,6) only it uses -> operator. When using an array I prefer d[0].xxx instead of the pointer operator because it more clearly describes what that code is doing.

chaienbungbu commented: Thanks. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

hi thx for reply, but i will be grateful if you suggest corrections in my existing program !!!!

I did. My suggestion is to rewrite it. The code you posted is much more difficult than it needs to be. There's such a thing as over-thinking a problem.

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

@Saba: The code you posted is pretty bad. It uses void main() instead of int main(), uses depreciated header files (c++ no longer uses .h extension in its standard headers), and mixes C and C++ strings, and adds absolutely NOTHING to the thread that has not already been said.

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

More than likely that program (Form1.exe) is still running in the background. Do Ctrl+Alt+Del to get tack manager then look at the list of running applications. If Form1.exe is listed there then try to kill it. If not, then you may have to reboot your computer to get it out of memory. I get that problem too on rare occations because the program will die to to program bugs.

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

>> Y we use DLL files?

Answer: Y not?

>>where we should use DLL files and where not
DLLs are never actually required -- the same thing could be accomplished by using statically-linked libraries. But then that would make the operating system and all the programs on it very very huge. You might not have a large enough disk drive to hold all that duplicate code.

One case is internationalizing programs. Instead of writing a whole program for each language (e.g. Entlish, Spanish, German, Chinese, etc) it can be done by writing language-specific resource DLLs. One program, many language-specific DLLs.

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

I'm only 39 years old (see Jack Benny) with 30 years more experience.

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

the \ character is a special character in c/c++ and has to be escaped, meaning you need two of them remove ("c:\\users\\asus\\new.docx");

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

What about the fact that there is no mention of a deity anywhere in the United States Constitution?

Exactly my point -- The constitution does not state that US government can not practice a religion.

Or the fact that Thomas Jefferson - author of the Declaration of Independence, founding father, and third President of these United States - coined the phrase in a letter written to Danbury Baptists, in which he referred to the First Amendment to the United States Constitution as creating a "wall of separation" between church and state.

Not relevant. TJ does not speak for the Constitution. That was only his opinion.

The United States Supreme Court also recognizes the separation of church and state. First in 1878, and then in a series of cases starting in 1947.

Yes there have been a lot of court cases about this, but not one of them said the Constitution required separation of church and state. Just one example:
Marsh v. Chambers

Facts of the Case:

Chambers was a member of the Nebraska state legislature who objected to its chaplaincy policy. The clergyman who opened each session with a prayer was paid by public funds. The District Court objected to the use of public money to pay the preacher�s salary while the Appellate Court objected to the prayer being offered.

Decision:

By a 6-3 vote the Supreme Court permitted the practice of beginning the legislative session with a prayer given by the publicly funded chaplain.

And …

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

Will you all donate $30,000.00 USD to me so that I can buy a new Toyota Prius?? Just deposit all your money in my PayPal account. Its nice, shiny new car that will give me lots of pleasure to drive.

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

I really really HATE two things about your code style: (1) CAPITALIZING FUNCTION NAMES, and (2) typedef'ing standard c++ class names. All that accomplishes is making your program more difficult to read and understand. You should be coding for clarity, not attempting to impress your teacher or others with an obnoxious coding style.

mrnutty commented: I really really hate that too +3
jonsca commented: I wasn't gonna say anything... hehe. I figured OP missed FORTRAN since he had a READ method (no WRITE(*,*) though) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Read this article about how to pass strings between VB and c++

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

>>this is the question and i want functions for the highlighted.
Well, you're not going to get it here. You will have to write the function yourself.

How to sort the names will depend on how you have the names stored in memory. There are lots of sort algorithms, but the easiest to code is the bubble sort. You will need to write two different sort algorithms, one that sorts the strings and the other that sorts the integers.

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

Somebody forgot to read the Forum Rules as requested multiple times upon signing up.

Naw -- he just simply ignored them.

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

1) Depends on how quickly you learn. When I started I had nothing more than a book and an old Radio Shack computer with *nix-like os. I learned enough in about a month to get my first programming intro job with Account Temps (temporary employment agency). But that was mid 1980s and times have changed a lot since then.

>>Based on the summary provided in the second link, how much of the language does the book cover?
It's a beginner's guide so it only covers the very basics of the language. There is a lot that is probably not covered, such as containers and algorithms.

2. That's an excellent compiler and IDE, and its all that you need to get you started learning c++. Code::Blocks with MinGW is also excellent. As for books, all you need at first is an Intro to C++ book, see the Read Me threads at the top of this c++ forum for other book recommendations.

3. Old c++ will NOT become obsolete. The new standard will just add to the existing c++ standard. Once the new standard is released it will be several years before it is implemented by compilers. Some compilers still have not implemented everything in the current c++ standard. Microsoft VC++ 6.0 compiler is notorious for its lack of adherence to c++ standards.

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

Those are standard C++ libraries and implementation is nearly identical in all c++ compliant compilers. Unless you can provide us a specific instance where the two implementations are significantly different then your concern is unfounded. If you use Code::Blocks on both os then there will be no difference in how the standard libraries are implemented. I understand that some software houses only use Microsoft compilers, but that has to change when opting for cross-platform programs. And if you don't change then you will probably never get the project off the ground, or sit around waiting for several years until some miracle happens like Microsoft porting Visual Studio to *nix.

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

@crarn: IMO your best solution would be to use Code::Blocks/MinGW on both MS-Windows and Ubantu. I like Microsoft compilers a lot too, but it isn't cross-platform to *nix. OpenGL would be the engine you need, not DirectX. It seems to me that you need to be more open minded and use the tools that produce the end-result you want instead of attempting to force the end result to meed the tools that you like.

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

didn't you read this. It was the second google link hit

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
  1. Don't clear the screen because there may be information on the screen that people want to see. But you could use something like system("cls") or write your own cls() function using os api calls.
  2. namespace is just an umbrella used to keep symbol names from colliding with each other. It just groups together names/classes/structures/objects.
  3. getch() has nothing to do with the how to declare main(). main should never be declared as void because it always returns an integer whether you tell it to or not. Even if you omit the return statement main() will return an integer anyhow.
  4. Yes -- the syntax for a structure has never changed from day one when K&R was written.
  5. c++ does not require an explicit return statement -- main() defaults to 0 if you don't tell it to return something else.
  6. You can use them all except iostream.h, iomanip.h -- all you have to do is omit the extension on those two leaving <iostream> and <iomanip>.
  7. Put a 'c' in front of those names, such as <cmath> and <cctype>. The only difference is the compiler will put them under std namespace.
Salem commented: Nice +18
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The . operator tells the shell to look in the current directory for the program. Without the dot the shell searches all the directories listed in your PATH environment variable for the program and executes the first one found.

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

That's a famous behavior of MFCs Close button -- the Close button is activated when the Enter key is pressed. One way to fix that is to catch the WM_CLOSE event and ignore it, but then you might not be able to close the program at all.

Another way is to catch the return key in OnTranslateMessage(). This is for CDialog, but you can do the same thing in any type of MFC program.

BOOL CTestmfcDlg::PreTranslateMessage(MSG* pMsg) 
{
	if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
	{
		return FALSE;
	}
	return CDialog::PreTranslateMessage(pMsg);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I am using the real version of google so i don't need any site of this kind.

That site is used to give a sarcastic answer to other people who could have used google to get quick answers to their question instead of posting the question here. If you don't help other people here then you would probably not use that site.

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

That's only a very small part of debugging facilities. With Microsoft all you have to do is double-click an error message and the cursor will appear on the line that caused the error. You were probably doing it the hard way.

There is a great deal more to debugging then just finding lines that contain errors.

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

I prefer VC++ 2008 Express (or any other edition) because of its superior debugging tools. I have yet to see another non-Microsoft IDE that matches the debugging features and ease of use that VC++ 2008 has. The remaining features of that IDE are more eyewash than anything else and have been matched by other IDEs such as Code::Blocks.

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

I've been using that for quite some time.

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

It just doesn't make much sense to give a chicken elaborate rights and then eat it.

My thought about animal rights is not to treat them as humans, but to treat and/or kill them humanly -- animal rights does not prohibit slaughtering chickens for food, but rather raising them so that they are not always in pain, starving, living in swallow, etc. I read a report not long ago about some sick cows that were taken to the slaughter house, some could only crawl in because they were so ill and in pain. I've seen news reports on TV about horse farms where the horses were without food and water, they were so skinny that we could see the outline of all their bones. And we see similar reports about a dog breeder. These are the kind of things that need to be stopped.

As for clones -- IMO a human clone should be treated just like any other human. How would we know that someone was a clone ? Does a clone wear a big C on his/her forehead, similar to the H (for hologram) that Rimmer has on the sitcom Red Dwarf? When you pinch a clone does he not cry? When you tickle a clone does he not laugh? When you cut a clone does he not bleed ? Does he not have fingerprints, or finger nails that grow, or hair that grows?