WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When dealing with pointers, the "&" sign is called the address-of urinary operator. Knowing it's name sure helps to understand when to use it. Is "*" a urinary operator as well, and if so, what is its name? If it is not an operator, then what is it?

Thanks.

Urinary? I know these questions piss off some people, but really! :icon_twisted:

To answer your question, see this. Google is your friend.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It is really difficult to make comments on multiple posts which happens often enough to be a pain in the ass since you removed the multi-quote button.

PLEASE give it back!

jonsca commented: Only because you said please. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Good to know. It works with MinGW in Code::Blocks.

Maybe so. But 3 years from now when you move to a new compiler and the code you've been using for the past 7 years suddenly doesn't work anymore, are you going to remember it might be because if fflush()? What's the chance your reaction will be "but it's always worked before!"

Stop using it now and get a jump on good habits.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Nathan is partially correct. Based on your code and assumed knowledge
1) read file 1 into an array.
2) read file 2 into an array.
3) merge the 2 arrays into a third.
4) write the 3rd array into file 3
5) Do not use sort in C++ because I'm sure your instructor wants you to learn the technique, not the C++ command.

Step 3 is the complicated one.
1) Start the indicies for array1 and array2 at 0
2) Compare the elements in array 1 and 2 based in the indecies.
3) Move the smaller (say array1) into array3. Move to the next element in array1.
4) Repeat 2&3 until all elements have been moved.

You'll have to figure out what to do when you get to the end of one of the arrays.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

That is a partial answer. The function strncat does in fact add a null character to the end if str1 was not overflown. If str1 was in fact overflown, then the null character is not added.

Again, you are wrong. The NULL is added, just not where you want it to be.

As I implied, write a test program:

#include <stdio.h> 
#include <string.h> 
int main() 
{ 
    int so, sl, n;
    char  str1a[20] = "abcdefghij";
    char  str1b[20] = "abcdefghijklmn";
    char  str1c[20] = "abcdefghijklmnopq";
    char  str22[20] = "1234567890";

    strncat(str1a, str22, 7);    printf("<%s>\n", str1a);
    strncat(str1b, str22, 7);    printf("<%s>\n", str1b);
    strncat(str1c, str22, 7);    printf("<%s>\n", str1c);

    printf("12345678901234567890\n\n");

    printf("<%s>\n", str1a);
    printf("<%s>\n", str1b);
    printf("<%s>\n", str1c);

    return 0;
}

Now why did the last 3 printf 's display what they did? Think about it... :icon_wink:

dotancohen commented: Thanks! +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is n? Is it strlen(str2)?

strncpy(str1,str2,n) -- definition

The issue is that I cannot be certain that the length of str1 is enough to hold both str1 and str2. Such as:

char str1[16]="Have a very ";
char str2[16]="nice day!";

What would sizeof(str1) give you?
What would strlen(str1) give you?
What's left?

From this page:
http://www.cprogramming.com/tutorial/secure.html
"You should be aware that strncpy will not automatically append a null terminator"

From http://www.cplusplus.com/reference/clibrary/cstring/strncat/:
Appends the first num characters of source to destination, plus a terminating null-character.

http://en.wikipedia.org/wiki/Strcat#strncat
The most common bounded variant, strncat, only appends a specified number of bytes, plus a NULL byte.

http://www.elook.org/programming/c/strncat.html
The function strncat() concatenates at most count characters of str2 onto str1, adding a null termination.

So your source seems to be wrong. What was the result of your test to see which is correct?

dotancohen commented: thanks +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Are you kidding me with this post?
1) Title: C++ Program -- Really? I never would have guessed! In a C++ Programming Forum I figured the post would be about making hamburgers.

2) Post itself -- and what are we supposed to do with this information? Write it? Give a detailed explanation of what you don't understand? Print it out and wash the windows?


Thread closed.

Salem commented: Now that's what I'm talking about! +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

OK Guys, enough showing off. Let's help Sonia11 and less trying to impress her with your prowess. I'll bet she's not interested in your C++ muscle and just wants to finish her project.

NathanOliver commented: well said +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm not going to use it, I was just taking the "C programming" skills test on oDesk, and it always uses "void main()" or "main()" and it's god-awful garbage code on the test the whole way through.

I still plan to use oDesk though because the testing thing is at least a nice idea.

Sorry, but that sounds stupid. If you want to increase you skills, why use something that doesn't have the skills you need? Would you ask your little brother to check your calculus homework? Would you ask an armless man to teach you to shoot baskets? Would you ask a blind man to teach you to draw?

Garbage code is garbage code. What positive things can you actually learn from it? You're fighting the learning process all the way.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Gee, I wonder what you types in. I also wonder what answers you got.

Any help is dependent on the input and output.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>> Do ensure that all posts contain relevant content and substance
>> and are not simply vehicles for external links, including signature links

Not necessarily an either/or. What about people who post stuff like you just posted ("thank you diz iz greeeeat post!") but who don't have an ulterior motive like spamming, but rather just an imbecile who, while possibly thinking he is adding something, isn't. Does the inane post lacking substance break a rule in and of itself? Other than the leet-speak?

Do ensure that all posts contain relevant content and substance is the rule.
and are not simply vehicles for external links, including signature links is simply a dangling statement that has no real bearing on the rule. The 'rule' includes many types of posts that are not allowed, whereas the dangling statement includes only one explicit type and therefore confuses the rule. Restating the rule without the confusion:
Do ensure that all posts contain relevant content and substance. For example, posts that are simply vehicles for external links (including signature links) are not allowed.

IMAO.... :icon_wink:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What problem? We didn't write the code so we don't know if it's right or wrong either. It might help to tell us what you're having problems with. We aren't psychic -- we're programmers.

Salem commented: But I knew you would say those things... +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Define alignment. I for one have no idea what you're talking about.

Salem commented: Ditto +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You would. It's lame, rigid, and two years old. There are much better ways, and many have been posted in the past two years.

mattdeximo commented: you are a big help in my activity thankyou +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As to human evolution, it's impossible to predict and there are many contradictory ideas.
I myself believe it's either stagnant or reversing,...

So we're becoming apes again? In some cases that's certainly looks true :icon_razz:

... as there's no longer any competition based on genetics going on to select the best traits for the next generation and in modern countries it's those who're least productive and least important for the survival of the species who breed the fastest, the mentally and physically deficient, the lazy, the incompetent who can't or won't hold a job and actually make something of their lives.

Check out the movie Idiocracy -- it shows a possible result... :icon_twisted:

frogboy77 commented: funny idea poor film +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Then, after you do what Adak suggested, on a piece of paper draw 2 empty matrices labeled arr and barr. Label the left sides and tops based on the indices used in the program posted. Now follow the program line by line, recording values of all the variables.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No wonder you're confused.

I am using Dev-C++ and when I am trying to compile a program in it, it is showing many errors. All the settings seems to be right. Can I compile a program including header files like conio.h and iostream.h and using namespace std in Dev-C++?

You are using 3 different eras of programming

  • 1980's - conio.h from non-Standard C programming. Suggestion - remove it and all functions used from it.
  • Pre-standard C++ using iostream.h -- again old and substandard. Upgrade to iostream, no extension.
  • namespace std for use with today's standard headers with no extension.

Decide what era you want to compile and fix the code to that standard.

confused_one commented: thank you sir for your suggestion +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Set up another variable (power) set to 1

Use a loop.
As you go thru the loop
1) Mult power by num1 -- n^i
2) Divide by loop index
3) Add/Subtract that value from a total

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Doesn't anyone know how to write a simple test to figure out something that they don't quite understand?

#include <iostream>
using namespace std;
int main(int ac, char *av[])
{
  int i;
  cout << "Arg count = " << ac << endl;
  for (i=0; i<ac; i++)
  {
    cout << "param " << i << "  " << av[i] << endl;
  }
  return 0;
}

Learn to write these test programs. It will save you hours of pulling your hair out and waiting for someone to answer forum questions.

Celtrix commented: thanks for the info +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's just the same old tired "It's crap", "God loves us all", "Allah [PBUH] is the one true God", interspersed with the odd bit of interesting observation. This however blends into the background after about 90 replies.

I say believe if you believe, don't if you don't. If you're not sure, why the hell not believe? Edge your bets, go to Church, sing your hymns, say your prayers before bedtime. Will it stop you getting a terminal illness, or stop your girlfriend from leaving you? Probably not, but at least you'll still have that superior feeling that comes with being part of a special gang. There's nothing like looking down your nose at people is there?

Yeah, I'm done, too. I was hoping to continue with a discussion of ideas but every time the Bible-thumpers show up it always degenerates into "it's true because I know it's true. Just look at a snowflake to see the the truth. Why do you hate me?"

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And why would you want to bother doing anything like this?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

hi
help me in resolving these questions

Sure.

Open your book.
Read each chapter.
Look at question #1.
Look up how to do a factorial.
Write the code.
Look at question 2.
Figure out an exchange rate.
Use that rate in a program to convert currency.
Continue....

NathanOliver commented: Great Advice +9
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Your IF statement is always true. Write a truth table and see why.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

#INCLUDE <IOSTREAM.H>
#INCLUDE <CONIO.H>
#INCLUDE <GRAPHICS.H>
void main()
{
CLRSCR();
GOTOXY(1,25);
}

:( So much shouting... So much anger... This used to be such a happy place... :icon_twisted:

jonsca commented: I was going to put in a dos.h just for you. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Is there really any other kind? ;)

Yeah, LISP. It'th all parenthetheth. No bracket'th at all. :icon_twisted:

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use the second one. The first one is crap.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It's because your Illiterate and make silly comments anyway Wenbnet.

Who's illiterate? Literate people know the difference between your and you're.

iamthwee commented: lazyness just lazyness! +0
Ezzaral commented: Exactly what I was thinking too. +0
debasisdas commented: :) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at the string character by character.

vedro-compota commented: + +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I don`t use allegro timers because I don´t know how to use them.
Can you teach me how to use them?

Oh, absolutely! Here you go. Anything else? We're here to serve.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Allow me :icon_rolleyes:

Maybe you can learn something from this post...

Saith commented: Awesome :D +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'm back too... just saying.. XD

HIDE!!! :icon_twisted:

Portgas D. Ace commented: ;) +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Because you are using .eof to control your loop. See this. feof() is exactly the same.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

and i don't get what's with this " if character = '\0' -- this will indicate a function key has been pressed"

A function key is actually 2 characters. Try this code:

#include <stdio.h>
#include <conio.h>
int main()
{
    int ch;
    
    puts("Hit Keys: ");
    do
    {
        ch = getch();
        printf(" <%02X>", ch);
    }  while (ch != 0x20);
    return 0;
}

Press SPACE to exit

You should write small snippets like this to test stuff you are unsure of. It saves time and you learn a lot more by writing even more code.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

can anyone let me know if what i'm doing here (the collision checking) it's ok??
the code looks something like this:

#define UP 72
#define DOWN 80
#define LEFT 75
#define RIGHT 77

void right(int &x, int &y, int sta, int end, int r){
do{

map();
	setcolor(YELLOW);
	setfillstyle(1, YELLOW);
	pieslice(x, y, sta, end, r);
	x+=5;
	delay(100);
	cleardevice();
	}while (!kbhit());  //i need to know over here too what to modify
}

do{
		
		for(i=1; i<=21; i++){
		for(j=1; j<=25; j++)
		 input=getch();
		 if (input==RIGHT)
				if(a[i][j+1]==0) right(i*20+5, j*20+95, 100, 100, r);									      //else - do nothing, it's a wall
				if (input==LEFT)
				if(a[i][j-1])==0) left(
				.......//and so on
		
		}while(input!=27); //stop when ESC is pressed

Not really.
You don't need 2 loops. One will suffice. Inside that loop:

If kbhit() returns TRUE
   get a character (getch())
   if character = '\0'  -- this will indicate a function key has been pressed
      get a character
      set up a switch on the character
         case of UP,DOWN,LEFT,RIGHT - process the direction key
      endswitch
   else
      process a non-function key
   endif
endif
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Who cares? If you really want your -40 back I'm sure we can down vote all your posts in this thread to get you back there if you really want us to.... :icon_rolleyes:

jingda commented: You are so bad +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please find someone to help you translate your question into English. The translation program you are using creates unintelligible giberish.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

is it possible to copy a zip file and exe file from one directory to another using c program?

Yes.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I doubt it. It's going to take detective work on your part to find out. Ever watch "Cold Case Files"? That's what you're up against. Trying to figure out what works today with 20-30 year old compilers is going to take time and effort to get the answers you need.

jonsca commented: Bring your pickaxe and headlamp, because in the Borland Museum they don't take American Express... +14
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I apologize that did not come out how it should have

Is this supposed to mean something?

My guess is your second command line parameter for the write file is bad. And it doesn't already exist since you are using the OPEN_EXISTING flag.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Each compiler is written specifically for the OS it runs on. The compiled program therefore runs only on the OS it was built on.

Standard C/C++ relates to the source code. All compilers should accept any C/C++ code that was written to the C/C++ Standard and output a working program.

Therefore, writing Standard C/C++ should compile using any compiler.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I agree. AD commented as he saw it, explaining why he would suggest not doing it. Then you became belligerent and condescending.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Looking back on your code, #1 is stop using TABs to indent. Use 4 SPACEs. Your IDE can be set to convert TABs to SPACEs. And be more consistent with your indentation. See this.

Also, before you even touch the computer, design the program in pieces on paper. Take each step needed in the program and break them down into smaller and smaller pieces. Once you get them small enough, program one main piece at a time. Test. Correct. Test again. When it works, add another piece.

For example, what's your input look like? How do you input that data? Where does it get stored? Do you have to convert it? How? Program it. Test it. Make sure it works.

Do not write the entire program and try to compile. You'll spend an hour typing it in and hours trying to figure out what's wrong. Rather spend the hour at your desk. Then spend minutes typing in a piece, and minutes testing to get it right. Then another few minutes typing in and another couple minutes getting that right.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We have flag bad post. We have infractions. We have rep.

Maybe we need a button for whiner!

Steve Nelson commented: You should get one for your account +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... post back with something like, "well, my function does this when I put inputs X, Y, and Z into it, but I'd expect it to do something else."

Almost. Post back with
"well, my function does this when I put inputs X, Y, and Z into it, but I'd expect it to do this instead."

We don't want you to just say "I expected it to do something different" like so many people do. Explain everything in detail.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i am trying to write a program to play the Battleship game;It is not a homework problem just a practice problem.

Good program to practice on. Well done.

The instructions are: set up a coordinate grid, select your own ships and locations while the computer selects its own; launch missiles by entering coordinates and accept hits from the computer.

Yes, that's how BShip works -- for the most part.

Thanks :)

You're welcome.

Nick Evan commented: :) +16
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

>>A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.


To clarify, you're saying...

for(int i = 0; i < 10; i++)
{
    // code
    i = /* whatever */  // <--- bad
    // code
}

Correct?

IMO, yes. Using the OP's question directly, the loop would be:

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) i = 11;
    // code Keep going
}

is better served by

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) break;
    // code Keep going
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In this case it's perfectly fine. You don't really have what's called a loop counter. You have variables that are tested in the while statement.

A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You compile both .cpp files into your project. The linker will take care of the rest.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

use cout 's to follow your program:

Is your input completely correct? Display what you read and verify it's accurate.

Is your sort testing the correct values? Again, display what you are testing and at least whether or not the values get swapped. You probably don't need to display each value being swapped, just that you're swapping.

Watch for an unexpected value, like going through a loop too many times, or not enough times.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

When a post is moved, could you please change the post icon from the purple new to the grey nothing immediately? Leaving it a purple new causes problems as we click on the 'new' icon, since that's what we see.