Narue 5,707 Bad Cop Team Colleague

Capitalizing the first letter of every single word makes your sentences harder to read.

>I Have Thought Of Shift, Shift-rotate Etc But Can't Figure Out How To Do It
You're probably trying to do it in-place and that's confusing you. Try building a whole new value by ORing the least significant bit into the new value, shifting the new value left and trimming the least significant bit from the old value:

#include <limits.h>
#include <stddef.h>

#define NBITS(x) ( sizeof (x) * CHAR_BIT )

int reverse_bits ( unsigned value )
{
  unsigned int rv = value;
  size_t n = NBITS ( value ) - 1;

  while ( ( value >>= 1U ) != 0 ) {
    rv = ( rv << 1U ) | ( value & 1U );
    --n;
  }

  return rv << n;
}
Dave Sinkula commented: Nice little optimization of the loop. +12
Rashakil Fol commented: I like how the solution is wrong in multiple ways. +6
SpS commented: Nice +4
Narue 5,707 Bad Cop Team Colleague

A stringstream is still a stream. You can seek on it:

#include <iostream>
#include <sstream>

int main()
{
  std::stringstream sin ( "123456789" );
  int value;

  sin.seekg ( 2 );
  sin>> value;

  std::cout<< value <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>This site is bogus...
It would be if we ever claimed to be a homework service. We never made that claim, so calling us bogus because you failed to read our rules is kind of stupid.

Jade_me commented: Good take +1
Narue 5,707 Bad Cop Team Colleague

>writer<<name[x]; //i know this isn't correct,, just to show what i m trying to do
Actually, that is correct, provided you overload the << operator for your class:

class Name {
public:
  set(int, string, string);
  friend ostream& operator<< (
    ostream& out, const Name& obj )
  {
    return out<< obj.id <<": "
      << obj.lastName <<", "<< obj.firstName;
  }
private:
  int id;
  string lastName, firstName;
};
k2k commented: thx alot... i just have to study some more about friend " +1
Narue 5,707 Bad Cop Team Colleague

The only one I know of is absolutely ancient, and it doesn't seem to be available on MSDN anymore. There are plenty of books on the subject, but if you want online freebies, you'll have to do some netdiving on google.

Narue 5,707 Bad Cop Team Colleague

I don't understand what you want to do. Can you be more specific?

WolfPack commented: gasp! you are a supermod and you don't know what postfix is? heavens! +7
iamthwee commented: Actually, she knows what postfix is, the example the OP gave certainly wasn't, hence the confusion. +13
Narue 5,707 Bad Cop Team Colleague

is there a benefit to knowing the classical data structures and algorithms despite the fact that they are incorporated in java api and dot net framework and someone might at any moment do the same for c or c++?

I can't imagine the comfort level of being handed everything on a silver platter that breeds this kind of question. The answer is absolutely, yes. Just because tools are provided to you doesn't mean you can get away with not understanding them, not knowing how they work, and not knowing how to sidestep them if necessary.

>the reason why i ask is that i do not want to waste my time learning
>them since it seems that they would not be needed for long.
From a practical standpoint, simply learning classic data structures and algorithms makes you a better programmer. Not because you know a specific implementation, but because you understand the concepts behind a solution such that you can apply it to your own problems. For example, you're not likely to need to write a quick sort implementation, but divide and conquer is an extremely valuable and general problem solving technique.

Ravenous Wolf commented: for what little my rep altering power is worth. thanks. +1
Narue 5,707 Bad Cop Team Colleague

Amazingly enough, it is.

Narue 5,707 Bad Cop Team Colleague

Why don't you run it and find out without needing to predict?

iamthwee commented: Endorsing the use of the antiquated (Turbo c), void main() etc is strictly forbidden. -2
Ancient Dragon commented: equalizer -- your post looks ok to me :) +21
Jishnu commented: I agree :) +2
Narue 5,707 Bad Cop Team Colleague
jephthah commented: well done +10
Narue 5,707 Bad Cop Team Colleague

>public static double max(double[]x)
This signature suggests that you're supposed to pass an array of doubles to the function and the function returns the largest of them. Your code doesn't do that at all. Use this as your driver:

public class Problem8
{
	public static void main(String[] args)
	{
		double[] check = {1,2,3,4,5,6,7,8,9};
		
		System.out.println(max(check));
	}
	
	public static double max(double[] x)
	{
		// Find the largest value in x and return it
	}
}
iamthwee commented: Your class name indicates you have tried 7 times before and failed :) +13
Narue 5,707 Bad Cop Team Colleague

>Ho can I get around this?
You'll have to learn about working with multiple threads or multiple processes. That's a rather broad and complicated topic for a forum post though, try google.

CodeBoy101 commented: Very helpful, he gave the perfect solution! +1
Narue 5,707 Bad Cop Team Colleague

>There is no quick solution.
That's a rational opinion. The appropriateness of spanking (since that's the topic of this thread) is situational, though I get the impression that too many people see it as a malicious beating rather than a means to bring attention to wrongdoing. I'm sure to get heat for this, but spanking a kid is just like smacking a puppy on the nose to train it. It's just painful enough to get their attention and inform them that they did something wrong. Assuming the requisite measure of intelligence they'll learn not to do it again.

Lack of training results in lack of experience, and hence, lack of discipline. It's better to learn these lessons early, so my opinion is that I should have the option of spanking my child if I feel it's needed.

Narue 5,707 Bad Cop Team Colleague

>what would you do if you had millions/billions of dollars to spare?
The same thing nearly everyone else on Earth would do: spend it selfishly, and maybe donate as little as possible to shut up the people who feel the need to tell me what to do with my money.

Sturm commented: Good idea except without the donation part +2
Narue 5,707 Bad Cop Team Colleague

Try flushing the stream after the file is printed. cout isn't tied to your file stream, so a read isn't going to force a flush, and I'm willing to bet that the file isn't large enough to fill the stream buffer:

temp.close();
cout.flush();
getch();
Karkaroff commented: that works!!! +1
Narue 5,707 Bad Cop Team Colleague

>@Narue: Your good...i didn't comprehend what he was saying initially.
I wasn't always a good little programmer. Unfortunately, some of the stuff I did required fluency in various dialects of l33t.

zandiago commented: oh great...another language to learn. +2
Narue 5,707 Bad Cop Team Colleague

>Something should really be done about that, as I'm sure if that were
>an actual post, a warning would be issued from Admin at the very least.
Good idea. Reputation comments do fall under Daniweb's policies, so anyone who feels a comment was out of line can report it, and anyone who makes such a comment is eligible for warnings and infractions. Keep that in mind iamthwee.

iamthwee commented: sowwwy :) +13
Narue 5,707 Bad Cop Team Colleague

>Disagreeing with you is NOT abusive
I like it when people disagree with me because it creates an interesting conversation. However, disagreeing in the way you've done is completely unprofessional. If I were one of your clients, I'd tell you correct your attitude or lose my business. However, I'm confident that you won't listen to my advice, and you'll likely respond with another childish attack. In fact, I'm so confident of this that I'm going to close the thread.

jasimp commented: Some people just don't learn +4
Narue 5,707 Bad Cop Team Colleague

>If you are "reasonably sure" I will consider what you say abusive then we
>are not having a technical discussion; we are having a personal arguement.
If I don't think I'm being abusive and the rules of the forum match my opinion, then it's more likely that I'm having a technical discussion and you're being overly sensitive.

>If what you say makes sense, then you should be able to state it without being "unpleasant".
Please reread the text that you quoted. In your hurry to berate me for my opinion, you failed to comprehend it.

>BULL. (sorry if that is "unpleasant" but your statement is false).
The people who complain that I'm not being nice are usually the quickest to throw around insults. ;) Proof in point: I've been nothing but pleasant in this thread, yet you're treating me like dirt for no reason. This destroys any credibility you might have had, and ruins your chances of successfully debating your opinion that everyone should be nice.

So as my parting shot, I'll say to you what you said to me: If what you say makes sense, then you should be able to state it without being "unpleasant".

*plonk*

nav33n commented: are you a lawyer ? :P +1
Narue 5,707 Bad Cop Team Colleague

>That would be true of anything that we would like to remove.
It's especially devastating with iostreams.

>There already is a superior replacemenmt -- its the functions in stdio.h.
That's what I was afraid you'd suggest.

>There are a few (very few) things I like about iostreams
>but for the most part fprintf() is a lot easier to use.
Except when you want type safety. Except when you want to extend the standard interface (adding your own user-defined type to fprintf, for example). And of course, except when someone points out that format strings are a bitch to get right for all but the most twisted aficionados.

Narue 5,707 Bad Cop Team Colleague

>I don't agree with U.
You can disagree all you want, but you're still wrong.

>u can search "fflush" in MSDN!
MSDN doesn't define the standard library, the C standard does. And the C standard says that calling fflush on an input stream is undefined. If your compiler happens to support an extension that allows fflush(stdin) , feel free to use it. But until this forum is renamed to "C for Beair.GQ's compiler", you'll be promptly corrected if you try to encourage undefined behavior with constructs like that.

>and it's give the example like this:
MSDN's examples are well known to be examples of what not to do. The code you posted is broken in four places, has three instances of non-portable constructs, and three instances of non-portable usage. Using MSDN to back up your claims is a folly.

Salem commented: Well said, and beat me to it :) +12
Narue 5,707 Bad Cop Team Colleague

You might find this enlightening, but it's pretty in depth.

Jishnu commented: Excellent article :) +2
Narue 5,707 Bad Cop Team Colleague

>Saying these kind of things to people is just wrong IMO.
It's certainly borderline, but if I punished people for being borderline, I'd be a laughingstock because most of my own posts are borderline. ;) I like to think that we're lenient enough to allow freedom of discussion (and argument), but strict enough to stop it when it gets out of hand.

>calling someone sub-human or comparing him with massmurderers
>from the previous century (and calling them heroes...) are two
>completely different things.
That's debatable, and you might want to start a thread on it in the Geek's Lounge. I think it might start an interesting debate.

iamthwee commented: *Geek's lounge* pertains to one person, are you saying there is just one person in the Geeks' Lounge? :) +13
Narue 5,707 Bad Cop Team Colleague

>>pride
i think that makes no sense. sure some make enough money in their day job to not not need this but it still is usefull. and those whom are the best would have more signatures and earn more money so the more money you earn from signatures might be a reflection of how valuable a member you are.

It's not about money, it's about selling away your credibility. I'm probably an expert in my field, but I'm not about to use my name to sell products and services unless they're directly related to the forums I post in and I feel strongly enough about them to recommend them anyway. Putting links in my signature to the highest bidder reeks of a materialistic greed that a lot of geeks find repulsive.

uniquestar commented: Well Said Sir +3
~s.o.s~ commented: Except that it's not *sir*... +20
madoverclocker commented: well said +1
Narue 5,707 Bad Cop Team Colleague

>You're the picture of politeness
I scared away two or three people in the last month. Polite people don't do that. ;)

iamthwee commented: You're a softie at heart though :) +13
Narue 5,707 Bad Cop Team Colleague

>bool validUserInput (true);
This guy should be reset inside the loop. Right now if you fail once, it fails forever.

>if ( rate % 2 != 0 ) validUserInput = false ;
When rate % 2 is 0, the number is even. This test will set validUserInput to false when the number is odd, which isn't what you want.

>while (validUserInput);
Perhaps you meant while ( !validUserInput ) .

Compare and contrast:

bool validUserInput;

do {
  validUserInput = true;

  cout << "Please enter an odd value between 3 and 31: " << endl;
  cin >> rate;

  myWaveForm.getSampleValue( rate );

  if ( rate % 2 == 0 ) validUserInput = false ;
  if ( rate < 3 ) validUserInput = false;
  if ( rate > 31 ) validUserInput = false;
}
while (!validUserInput);
johnnyjohn20 commented: explained my problem thorougly +1
Narue 5,707 Bad Cop Team Colleague

>I would like to have a general format that would
>produce such arrays for any given parse tree.
It looks fairly simple. Just recursively traverse the tree and save the paths as you go:

#include <stdio.h>
#include <stdlib.h>

struct node {
  int data;
  struct node *link[2];
};

struct node *insert ( struct node *root, int data )
{
  if ( root == NULL ) {
    root = malloc ( sizeof *root );
    root->data = data;
    root->link[0] = root->link[1] = NULL;
  }
  else if ( root->data == data )
    return root;
  else {
    int dir = root->data < data;
    root->link[dir] = insert ( root->link[dir], data );
  }

  return root;
}

void get_paths ( struct node *root, int depth )
{
  static int path[100] = {0};

  if ( root == NULL ) {
    int i;

    for ( i = 0; i < depth; i++ )
      printf ( "%d,", path[i] );
    puts ( "\b " );
  }
  else {
    path[depth] = root->data;
    get_paths ( root->link[0], depth + 1 );
    get_paths ( root->link[1], depth + 1 );
  }
}

void dump_r ( struct node *root, int level )
{
  int i;

  if ( root == NULL ) {
    for ( i = 0; i < level; i++ )
      putchar ( '\t' );
    puts ( "~" );
  }
  else {
    dump_r ( root->link[1], level + 1 );

    for ( i = 0; i < level; i++ )
      putchar ( '\t' );
    printf ( "%d\n", root->data );

    dump_r ( root->link[0], level + 1 …
iamthwee commented: cute! +13
Narue 5,707 Bad Cop Team Colleague

>you may not have write access to your command line arguments
Both C89 and C99 say otherwise, and they both use exactly the same wording:

The parameters argc and argv and the strings pointed to by the argv array shall be modifiable by the program, and retain their last-stored values between program startup and program termination.

>Moreover, you can't change their size.
This is correct though.

>My aim is to swap two strings without using a temporary pointer
>or char array, but i have to use command line arguments for
>getting the two strings as input.
If the question is to copy the actual arguments (eg. argv[1] and argv[2]), the only viable solution would have to assume that both of those strings are exactly the same length:

#include <stdio.h>

int main ( int argc, char *argv[] )
{
  if ( argc > 2 ) {
    int i = 0;

    printf ( "Before: '%s' '%s'\n", argv[1], argv[2] );

    while ( argv[1][i] != '\0' ) {
      char save = argv[1][i];
      argv[1][i] = argv[2][i];
      argv[2][i++] = save;
    }

    printf ( "After:  '%s' '%s'\n", argv[1], argv[2] );
  }

  return 0;
}

>Please don't do that again!
Not enough information. Why shouldn't he do it again?

Ancient Dragon commented: good comments +21
Narue 5,707 Bad Cop Team Colleague

>Ask Bumsfeld!
No. You made the accusation, you supply the proof. I also won't accept hearsay. You tell me what thread posts were deleted from, and I'll verify whether or not your claim is valid. Deleted posts aren't actually deleted, they're marked as deleted and made invisible to non-moderators. So if what you say is true, you can point out a thread and I'll find a deleted post by jwenting that clearly doesn't break the rules. If, on the other hand, my personal opinion is correct and you've been making false claims, I'll tell you to cease slandering our moderation staff immediately.

I won't allow you to tarnish the good name of Daniweb by suggesting that any of the moderators are petty or unprofessional in their duties.

jbennet commented: exactly +21
jasimp commented: Well said +4
Narue 5,707 Bad Cop Team Colleague

>I want to know if that's a good idea, or what to look out for.
If your goal is C++, there's little point in side tracking yourself with C. But do keep in mind that C and C++ require different mindsets. Good C isn't necessarily good C++, and vice versa. Despite what you've heard, C and C++ are different languages.

>Has anybody tried the same thing and have some advice for me?
I learned C first. It didn't kill me.

>Next, I'm asking to be pointed to a nice C tutorial.
You'd be better off picking up The C Programming Language by Kernighan and Ritchie. Tutorials are too hit or miss, and that book has been the bible since the 70's.

>Is it true that to get objects you have to do it in C++?
No, but C++ certainly makes it more convenient.

scru commented: Cool. YOu covered just about everything. :) +1
Narue 5,707 Bad Cop Team Colleague

>So it's better to have base-protected-getters than protected variables?
Yes. Think of class design as a service and a client. The service supplies a guaranteed interface and the client uses the interface to do what it needs. This is most obvious in the public interface of a class for users of that class. However, it also applies to the protected interface of a class for the children of that class. If you make the internal data protected, it means that you can't ever change how the base class works or you'll break all of the clients, just like if you make the internal data public.

Narue 5,707 Bad Cop Team Colleague

The problem you're asking about is (text - '0') , which doesn't work because text is a string and not a character. You probably meant (text[i] - '0') . However, that's not going to be of much help because the rest of your program is horribly broken. Here are some examples:

>string encrypt(string text, string message);
>string decrypt(string text, string message);
This won't compile because you don't say using namespace std; until after the prototypes, yet the prototypes use an unqualified name that's in the std namespace.

>encrypt;
When calling a function, you must provide the argument list.

>temp = 3 + (text - '0') << endl;
You really don't want to use << here, and endl is nonsensical.

Koldsoul commented: Great feedback. Appreciate the great knowledge. +1
Narue 5,707 Bad Cop Team Colleague

>since i do not have any Industrial Experience..
It's a final year project. Just pick something you learned that exhibits your newfound skills and seems interesting. It doesn't have to be practical or viable in the market, so asking for advice from people with "Industrial Experience" is silly.

Narue 5,707 Bad Cop Team Colleague

srand seeds the random number generator. If you call srand too often, and the value you use as the seed (srand's argument) changes infrequently, you'll keep seeding the random number generator to the same thing and rand will produce the same sequence. This will give you an idea of how rand and srand work together, but the simple answer is that you should call srand once:

#include <stdio.h>
#include <time.h>

int gimme_random ( void )
{
  return 1 + rand() % 10;
}

int main ( void )
{
  int i;

  /* Call srand only once */
  srand ( (unsigned)time ( NULL ) );

  for ( i = 0; i < 10; i++ )
    printf ( "%d\n", gimme_random() );

  return 0;
}
Narue 5,707 Bad Cop Team Colleague

I believe GCC comes with Mac OSX. There's the Xcode IDE as well, but I'm not sure what compiler it uses. Unless you're using one of those Mac Minis, you should already have a compiler installed and ready to go.

>If i compile it on the Mac, will it work on a PC?
No. When you compile your code, it turns it into binary executable instructions that only work on the system that it was compiled for. However, if you write portable C++, you can recompile the code on the PC and it will work.

helixkod commented: awesome +1
Narue 5,707 Bad Cop Team Colleague

>ther was a possible answer....
Why waste my time with a "possible answer" when I could make you be specific and save my effort for an actual answer? :)

>nd,,thers nothin to moan about,,jss chill
First, to chill would mean that I'm somehow bothered, which I'm not. Second, you've just introduced even more for me to complain about with what can only be described as line noise in your post. What in the world makes you think that "nd" is a reasonable contraction of "and"? Two commas makes no sense at all, and "jss" isn't even remotely related to "just". If you want to learn C or C++, you need to learn to follow rules and have an eye for detail.

This is your post, corrected:

Even if I meant C and C++, there was a possible answer.
Besides, there's nothing to moan about. Just chill.

And don't get me started on "lolz". :icon_rolleyes:

I'm not doing this for fun[1], by the way. Many of our members aren't native English speakers and won't be able to make the connection when you butcher the language. Sure, it might make sense to you, but you're not the one who needs to comprehend your posts. If you make your posts hard to understand, you'll get less help. That's common sense.

[1] I also do it for fun.

jbennet commented: well said +21
Narue 5,707 Bad Cop Team Colleague

If it's actually an array, there are two common ways to find the size. The first is a template that converts an array of type T to an array of type char, which can then be used as the operand to sizeof to get the number of elements:

#include <iostream>

template <typename T, size_t N>
char (&array(T(&)[N]))[N];

int main()
{
  int a[10];

  std::cout<< sizeof array ( a ) <<'\n';
}

The other is a macro that divides the size of the array by the size of a single element to give you the number of elements:

#include <iostream>

#define length(a) ( sizeof ( a ) / sizeof ( *a ) )

int main()
{
  int a[10];

  std::cout<< length ( a ) <<'\n';
}

The template is type safe, and won't let you accidentally take the size of a pointer. The object must be an array. The macro will let you pass a pointer, but because a pointer isn't an array, the result will be wrong. Therefore, you should prefer the template method.

If it's not actually an array, but a pointer to the first element, you're basically screwed unless there's a sentinel value at the end of the array (like the '\0') in C-style strings, or you have the size stored elsewhere.

>For instance, if someone enters John, the function outputs 4.
If this is a C-style string, use std::strlen to get the length of the string, or use a loop to find the '\0':

Narue 5,707 Bad Cop Team Colleague

>thx in advance on trying to fooling me that u know what i need
So you don't need a compiler? Fine, what exactly does this mysterious "c++ program for vista" of yours do? If I suggest Word 2007 will you accept that as a valid answer?

>hehe dont worry in the end someone kindly not like u will help lol
I doubt it. Not only is your writing style painfully obtuse, you don't even seem to know what you want.

Nick Evan commented: Ah.. the beautifull sound of the chainsaw +2
Narue 5,707 Bad Cop Team Colleague

>I'm having some trouble understanding the advantages
>and disadvantages of using scanf over fgets.
I imagine because the comparison is difficult. scanf and fgets do different things. scanf is designed for formatted input and fgets is designed for unformatted input.

>But in what way does fgets prevent that from happening?
Assuming you use it correctly, the second argument of fgets provides a limit on the number of characters that are read:

char buffer[10];

if ( fgets ( buffer, 10, stdin ) != NULL )
  fputs ( buffer, stdin );

It doesn't matter how many characters you actually type, only up to 9 will be written to buffer, and the last spot will be '\0'. The same can't be said about a naive use of scanf:

char buffer[10];

if ( scanf ( "%s", buffer ) == 1 )
  puts ( buffer );

You can type 5000 characters, and as long as there's no whitespace scanf will read 5000 characters. The big question is, where does it write them all if buffer can only hold 10?

That's a naive use of scanf, and if you find yourself doing that, you shouldn't be using scanf at all, because you simply don't understand it well enough to use it safely. You can plug the buffer overflow hole with scanf like this:

char buffer[10];

if ( scanf ( "%9s", buffer ) == 1 )
  puts ( buffer );

By adding a maximum field width, you're telling scanf …

Narue 5,707 Bad Cop Team Colleague

I've been writing my own implementation of stdio.h whenever I get a few spare minutes recently. Nothing fancy or thorough, and without wide character support, it's hardly conforming. But I was looking at one of my intermediate versions of printf and could only marvel at how ugly it was. So much that I'm going to share. :)

Have a peek (and keep in mind that I have no intention of keeping it. ugh):

#include "format_string.h"
#include "jstdio.h"
#include "numeric.h"
#include "print_stream.h"
#include "xtype.h"

static int pad_buffer ( J_FILE_T *out, char buffer[], const char *prefix,
  struct print_convspec *spec, j_size_t *nwrit )
{
  char *p = buffer;
  int width = spec->field_width - j_str_len ( prefix );
  int prec = spec->precision;

  if ( spec->flags & LEFT_JUSTIFY ) {
    if ( spec->flags & SHOW_SIGN && buffer[0] != '-' ) {
      if ( _put ( '+', out, *nwrit ) == J_EOF )
        return 0;
    }

    while ( *prefix != '\0' ) {
      if ( _put ( *prefix++, out, *nwrit ) == J_EOF )
        return 0;
    }

    while ( *p != '\0' && --prec > 0 ) {
      if ( _put ( *p++, out, *nwrit ) == J_EOF )
        return 0;
      --width;
    }

    while ( width-- > 0 ) {
      if ( _put ( ' ', out, *nwrit ) == J_EOF )
        return 0;
    }
  }
  else {
    int show_sign = ( spec->flags & SHOW_SIGN ) != 0;
    int len = width - j_str_len ( buffer ) - show_sign;

    /* We want the sign …
Dave Sinkula commented: I'll hold those 7 gotos against you some day. ;) +11
iamthwee commented: I'll hold those 472 variable prefixed with your christian name some day. :P +12
Narue 5,707 Bad Cop Team Colleague

>Don't listen to her! She doesn't believe in you. I know you can do it!
If I can't do it, it's impossible without a good jump in human evolution. :)

twomers commented: Ah. You're not nearly modest enough! +3
Narue 5,707 Bad Cop Team Colleague

>well it is better if u can give straight 4wd answers...
Salem's answer not only was as thorough as possible given the complete lack of information you provided, it was also useful in other ways. So drop the attitude.

iamthwee commented: well said +11
Narue 5,707 Bad Cop Team Colleague

>But, is there any way to implement a portable function for this??
If you only allow the basic C++ character set, sure:

namespace {
  const char *upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const char *lower = "abcdefghijklmnopqrstuvwxyz";
}

int convert_char ( int c, const char *from, const char *to )
{
  int i = 0;

  while ( from[i] != '\0' && from[i] != c )
    ++i;

  if ( from[i] == '\0' )
    return c;

  return to[i];
}

int to_upper ( int c )
{
  return convert_char ( c, lower, upper );
}

int to_lower ( int c )
{
  return convert_char ( c, upper, lower );
}
Narue 5,707 Bad Cop Team Colleague

You're overcomplicating things, I think. Here's a sample without the "again" crap that should give you an idea of what's expected when functions get involved:

#include <iostream>

int findbig ( int num1, int num2 )
{
  return num1 > num2 ? num1 : num2;
}

void getnumbers ( int& num1, int& num2 )
{
  std::cout<<"Please enter two numbers to compare: ";
  std::cin>> num1 >> num2;
}

int main()
{
  int num1, num2;

  getnumbers ( num1, num2 );
  std::cout<< findbig ( num1, num2 ) <<" is larger\n";
}
GreenDay2001 commented: whoops..thanx for figuring out my folly, didn't noticed then, but my code was really crap +4
Narue 5,707 Bad Cop Team Colleague

>I dnt want to purchase a book as yet.
Then you're already walking on thin ice.

>Can any one refere me to a site from which I will be able to learn the basics relatively quick.
Yes. There's only one site that offers basic C++ tutorials that I'll recommend (until I write my own, of course), and that site is this one.

Dave Sinkula commented: Hm. Something new to check out. Thanks. +11
Narue 5,707 Bad Cop Team Colleague

>I have heared 'bout fsetpos but I did'nt know that it could deal with larger filetypes.
That's what fsetpos and fgetpos are there for. fseek is limited to the size of a long integer, but because fsetpos and fgetpos rely on an opaque type (fpos_t) for representing the offset, implementations should be using a type that can handle the file size limit of the system. If your compiler doesn't do that, it's safe to assume that the rest of the standard library may be weak as well.

>Which is more preferable between fseek64 and fsetpos?
Between two functions that do the same thing, but with one being standard and the other not, choose the standard function. But make sure that they really do the same thing. If I were to implement fseek64 on my implementation it would look like this:

typedef off64_t fpos_t;

off64_t fseek64 ( FILE *file, off64_t offset, int whence )
{
  return _intern_seek ( stream, offset, whence );
}

Which is identical to fseek because it uses fpos_t internally anyway. In other words, fseek64 would be a fluffy function for compatibility with existing code only. But I can't say how it's implemented on another implementation, so you'll have to do some research.

jaepi commented: Hell yeah. Thanks! +2
Narue 5,707 Bad Cop Team Colleague

>>It's too compact to be readable.
>Then the reader doesn't know C language very well, probably a newbe. Looks perfectly ok to me.

>>The tricks used are obscure.
>What tricks? And how are they obscure.

>>The mechanics are too subtle (notably, dealing with '\0').
>Not subtle at all if you realize what that loop is doing.
Okay, let's break it down by difficult concepts. Here's the original code, to save scrolling:

while( *outstr++ = *instr++);

1) You have to know the precedence/associativity of * and ++. This is a notoriously good area to screw up, even for experienced C programmers (to the point where ++ is often banned in complex expressions).

2) You have to know the implicit test made by a loop, and that it correctly checks for the end of a string. Experienced programmers usually have to think about this to get it right. I'm one of them, which is why my style calls for explicit tests except for exact boolean comparisons.

3) You have to know that because the condition is also an assignment, the null character is correctly added to the string without further logic.

4) You have to parse the entire line before realizing that the null body is intended rather than a grievous error.

That's a lot of prerequisite (not to mention intimate) knowledge for understanding such a simple operation.

>slower than what?
Other solutions that vary depending on the compiler …

n.aggel commented: great explanation! +1
Narue 5,707 Bad Cop Team Colleague

>Thats why I have no idea why its there?
It's there because a right shift may or may not fill the vacated bits with zeros. If the type of source is signed, the implementation could fill the bits with zeros (a logical shift) or the value of the sign bit (an arithmetic shift). The AND operation forces the same result as a logical shift, even if an arithmetic shift was performed.

Dave Sinkula commented: Holy cow. I haven't been giving you the points you've earned with your efforts. +11
Narue 5,707 Bad Cop Team Colleague

God, can't you stick to one forum? I hate splitting my answers between cprog and Daniweb.

Salem commented: I've taken to ignoring him on both forums. +11
Narue 5,707 Bad Cop Team Colleague

>helos...!!!
>wel am new to dis..!!!
>but i hav a code to it...!!!
>lets try out..!!!!!
You have one of the most annoying writing styles I've seen. If you want people to treat you like anything but an irritating script kiddie, use proper English. The non-native English speakers will thank you.

>try dis out dude..!!!
1) Your code uses a poor style.
2) Your code doesn't work.

Please test solutions before you post them, unless you want someone like me to rip them to shreds, like I'm about to. Let's start with the extremely poor style you're using (I even fixed the indentation for you when I added code tags):

>#include<conio.h>
This is a non-portable header. You'd do well to forget it exists until you're experienced enough to use it wisely, which you most certainly are not right now.

>void main()
There are two standard definitions of main:

int main ( void )
{
  return [I]<integer value>[/I];
}

and

int main ( int argc, char *argv[] )
{
  return [I]<integer value>[/I];
}

The portable return values are 0, EXIT_SUCCESS, and EXIT_FAILURE. The latter two are macros defined in stdlib.h.

>int i,j,count=1,flag,arr[5],p[5];
Each variable should be declared on a separate line. This makes it easier to read, document, and maintain your code. It's also a good way to avoid bugs.

>scanf("%d",&arr);
Always check the return values of input functions. If you don't, you …

Dave Sinkula commented: They set themselves up, you knock 'em down. Fun for the whole family. +11