Narue 5,707 Bad Cop Team Colleague

>How can i do this??
Did you start by searching? Converting an integer to a string is a very common question.

Narue 5,707 Bad Cop Team Colleague

We can read you know. You don't have to capitalize the "important" words for us. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>Another solution could be something of this sort
If the user types letters, scanf will fail and leave i uninitialized. Accessing an uninitialized variable's value is undefined behavior. The suggestion becomes reasonable if you initialize to an invalid value for the program (like 0).

But then you've got the bigger problem of a dirty input stream in the case of letters. I hope you don't plan on taking any input after this, because there's no telling what you'll get. ;)

Narue 5,707 Bad Cop Team Colleague

>This is the first time I've ever seen this and I'm interested in any
>reasoning why we shouldn't just remove it to eliminate code bloat.

I can't claim to know what the original author was thinking, but I'm a fan of the double inversion for forcing an integer into a strict boolean 0 or 1.

Narue 5,707 Bad Cop Team Colleague

>Am I right? wrong? missing something?
That's a toughie. While a compiler might inline your function, it's best to assume that there will be overhead. However, the overhead of a function call isn't exactly significant these days, which is why it's generally better to modularize (your teacher's suggestion) than to rewrite inline as needed (your solution).

A good middle ground is an inline function that counts digits (though it's still not guaranteed to be inlined):

inline int digits(int value, int base = 10)
{
  int n = 0;

  do
    ++n;
  while ((value /= base) != 0);

  return n;
}

"Most efficient" doesn't necessarily mean "worst structure". ;) Usually you can use less than optimal code structure for readability and get the most performance benefits from well chosen algorithms. Only in uncommon cases will you need to go balls to the wall and squeeze every last cycle out of your code.

I think I'd side with your teacher on this one, though that's in terms of advice. I probably wouldn't deduct points.

Narue 5,707 Bad Cop Team Colleague

>Did you want us to post our solution here, or leave the question unanswered for others?
It's a personal challenge, not a contest, so you don't have to prove that you did it. However, if you want to share, feel free. I was planning on giving it a little time before posting my own solution, so as not to stifle creativity.

In all honesty, I'm hoping everyone can get together and collaborate on making all of the posted solutions better. That's the part of the challenge I think we'll learn the most from. At the very least there will be one solution (mine) posted and open to review.

Narue 5,707 Bad Cop Team Colleague

>there are more values in your sorted results than in the text file with the information to sort
My bad, I added some more cases, but forgot to post the updated text file. Feel free to use the posted input or add the cases from the output as well. Either will be acceptable.

Narue 5,707 Bad Cop Team Colleague

>pretty stupid reason I must say
A lot of things seem stupid when you're too ignorant to understand.

Narue 5,707 Bad Cop Team Colleague

Consider the following program and input file:

#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
#include "natural_compare.h"

struct natural_less: std::binary_function<std::string, std::string, bool> {
  bool operator()(const std::string& a, const std::string& b)
  {
    return natural_compare(a, b) < 0;
  }
};

std::vector<std::string> get_lines(std::istream& in)
{
  std::vector<std::string> v;
  std::string line;

  while (std::getline(in, line)) {
    if (line[0] != '#')
      v.push_back(line);
  }

  return v;
}

int main()
{
  std::srand((unsigned)std::time(0));

  std::ifstream in("test.txt");

  if (in) {
    std::vector<std::string> v = get_lines(in);

    std::random_shuffle(v.begin(), v.end());
    std::sort(v.begin(), v.end(), natural_less());

    std::vector<std::string>::const_iterator it = v.begin();
    std::vector<std::string>::const_iterator end = v.end();

    while (it != end)
      std::cout<<'>'<< *it++ <<"<\n";
  }
}
# Basic tests
a1
a2
a3
a10
a11
a12
# Matching value tests
b5
b 5
b05
b  5
b 05
b005
b   5
b  05
b 005
b0005
b    5
b   05
b  005
b 0005
b00005
# Second tier matching value tests
c 1 5
c 1  5
c 1 05
c 1   5
c 1  05
c 1 005
c 1    5
c 1   05
c 1  005
c 1 0005
c 1     5
c 1    05
c 1   005
c 1  0005
c 1 00005

The code obviously won't compile because the natural_compare function isn't implemented (we'll get to that shortly). But with a basic call to std::sort using the normal character ordering rules, the output would look something like this:

>a1<
>a10<
>a11<
>a12<
>a2<
>a3<
>b    5<
>b    5 <
>b   05<
>b   5<
>b   5 < …
mrnutty commented: Hope you post more challenges. +4
Narue 5,707 Bad Cop Team Colleague

>I also figure that the top secret moderator forum must get pretty boring
It does indeed. Though there's a separate forum for reported posts, otherwise any of the legit mod threads would get lost in the mess. ;)

Narue 5,707 Bad Cop Team Colleague

>I just looked at the code and figured it could never do what I wanted due to its simplicity.
Isn't elegant code a wonderful thing? :)

Narue 5,707 Bad Cop Team Colleague

>obviously your to high and almighty to answer questions for people that need help
I answered your question. Then you shot back with "I'm too clueless to understand anything, gimme code!".

>I hope you remember when you were programming early on,
>you were not born the capability to program anything

I remember quite clearly. I also remember that I didn't have anyone to lean on for help. I had to figure everything out by myself, so I'm especially unsympathetic toward newbies these days who have the vast resources that would have given newbies a spontaneous orgasm when I was learning, yet still can't survive without hand holding.

>Just a wild guess that, I am thinking your will into your 40s/50s, but thats just a guess.
Early thirties. Though I'm not sure how that's relevant.

JasonHippy commented: I remember those days too. Some bloody newbs don't know they're born! +2
Narue 5,707 Bad Cop Team Colleague

>I'll need you to shed more light on the true "next step" I should have taken.
You already asked that question, and I already answered it. Though obviously you didn't understand (if you read it at all), because there isn't a "true" next step. Everyone follows a different path. Learning how to write GUIs isn't the wrong decision, so you can relax. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

I want you to ask a smart question, but apparently neither of us are getting what we want.

Narue 5,707 Bad Cop Team Colleague

>As it stands now, I am getting a segfault.
I'm not surprised. You have the right idea in making a copy of the name to return, but you're attempting to return a pointer to a local variable, which is a bad idea. When a function returns, the local variables are conceptually destroyed. Thus, you can't use a pointer to the destroyed data.

If you don't want to use malloc, you really only have the choice of using an externally defined array to hold the name. For example:

char *pop ( char name[], size_t size )
{
  struct StackElement *save = stackTop;

  if ( strlen ( save->name ) >= size )
    return NULL;

  strcpy ( name, save->name );
  stackTop = save->next;
  free ( save );

  return name; /* Note: no indirection here */
}
Narue 5,707 Bad Cop Team Colleague
if ((letter >= 'A' && letter <= 'Z' ) || (letter >='a' && letter <= 'z'))
{
  printf(" %c is a CONSONANT\n", letter);
}

If it's a letter at all, you always say it's a consonant. If you separate error checking from processing, you can eliminate that problem:

if ( isalpha ( letter ) )
{
  switch ( toupper ( letter ) )
  {
  case 'A': case 'E': case 'I': case 'O': case 'U':
    printf ( "%c is a vowel\n", letter );
    break;
  default:
    printf ( "%c is a consonant\n", letter );
    break;
  }
}
else
{
  printf ( "Not a letter\n" );
}
jonsca commented: You are a true poetess of the source code! +2
Narue 5,707 Bad Cop Team Colleague

If you have a question about a specific error, post the error message. If you want to post code, use code tags.

>what is a better way too write this without getting an error
Well, seeing as how your syntax is horribly broken, I'd say start by cracking a book on C++.

Narue 5,707 Bad Cop Team Colleague

>That's pretty much how all the ads out there read.
I realized it was all bullshit when I read an ad requiring ten years of Java experience...in 1998. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>I'd be content paying my dues doing simple coding at first, figuring
>it'll take five years of experience anyway just to find out if I have any
>talent for this or not.

Typically it takes two years of workforce programming before you settle into a stride. Beyond that point it's unusual to make significant leaps in ability.

>Even though the ads all ask for top talent
Ads ask for pipe dreams. Don't judge yourself against the list of buzzwords than some HR grunt pulled out of their grab bag of cheap adjectives. If I compare myself against an ad, I'd be woefully underqualified for my own job. But my employer is in no hurry to replace me. ;)

>are there any outfits that'll take people with just the basics and work with them?
Of course. How do you think all of us got into the field? ;)

>My feeling is I'll learn a lot more if, while continuing to take
>classes, I do C++ coding, on a simple level, in a part-time job.

Aside from stuff like rent-a-coder, you're probably not going to find a part-time job doing C++. But you're right in thinking you'll learn more that way.

Nick Evan commented: Good one +0
Narue 5,707 Bad Cop Team Colleague

>There are a lot of programs that do not require GUI, console, or human interaction.
Sadly, there's a misconception (especially among beginners) that GUI programming is the "next step" toward being a real programmer. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>Is there any standard rules when we write the main function.
Oddly enough, there are. You have two 100% portable definitions of main:

int main ( void )
{
  /* ... */
}
int main ( int argc, char *argv[] )
{
  /* ... */
}

Equivalent types are allowed, such as char ** for argv, or a typedef. If the compiler supports something else, you can use it, but at a loss of portability. The third parameter is a common one:

int main ( int argc, char *argv, char *env[] )
{
  /* ... */
}

Returning void is another common extension:

void main ( void )
{
  /* ... */
}

There are three portable return values (four if you count the C99 standard): 0 for success, EXIT_SUCCESS from <stdlib.h>, and EXIT_FAILURE from <stdlib.h>. In C99 you can also omit the return statement and 0 will be returned automatically.

>But to my surprise, all these definitions are also correct .
For a rather loose definition of "correct". One learns quickly that in C, correct is not synonymous with "compiles with a warning or two".

Narue 5,707 Bad Cop Team Colleague

Bwahahahahahaha!

Narue 5,707 Bad Cop Team Colleague

>If the general optimization is to x & 1 , what's the issue?
I really don't have any issue with it, but in my experience, the majority will understand x % 2 better than x & 1 . I'm of the opinion that the more widely understood code is better unless circumstances warrant the alternative. If most of your work involves bit bashing, x & 1 would probably be the better choice.

Dave Sinkula commented: Danke. +13
Narue 5,707 Bad Cop Team Colleague

You can supply a predicate to the sort template from <algorithm> that does the comparison:

#include <algorithm>
#include <vector>

void sort_object_list ( std::vector<sometype>& object_list )
{
  struct compare {
    bool operator() ( const sometype& a, const sometype& b )
    {
      return a.z < b.z;
    }
  };

  std::sort ( object_list.begin(), object_list.end(), compare() );
}
Narue 5,707 Bad Cop Team Colleague

>I am just a beginner seeking help
I am helping you. Do you want to beg for "help" the rest of your life? I'm not going to just give you answers that a sack of gravel could find in a few seconds, but I'll gladly teach you how to help yourself and answer your more complicated questions in the process.

If you don't want that, just say the word and I'll not waste my time with you.

Narue 5,707 Bad Cop Team Colleague

>just wanted to learn more.
You might consider learning things that have a chance of being used outside of a classroom setting. Turbo C is pretty much dead except in out-of-date schools and historically interested hobbyists.

Narue 5,707 Bad Cop Team Colleague

>using namespace std;
You can remove this line by explicitly qualifying the std namespace on your names.

>cin.clear ();
>cin.get ();
>cout << endl;

These lines are unnecessary. Further, you can merge the input into a single prompt:

std::cout<<"Enter two numbers: ";
std::cin>> a >> b;

>cout << result; //Displays the result
>cout << endl;

These lines can be merged (and endl is often unnecessary):

std::cout<< result <<'\n';

>if (result % 2 == 0) cout << "your result is even";
>else cout << "your result is odd";

You can make use of the ternary operator here:

std::cout<<"Your result is "<< (result % 2 ? "odd" : "even") <<'\n';

>std::cout<< result <<'\n';
>std::cout<<"Your result is "<< (result % 2 ? "odd" : "even") <<'\n';

These two lines can be merged, but the line length starts getting awkward:

std::cout<< result <<"\nYour result is "<< (result % 2 ? "odd" : "even") <<'\n';

>cin.clear ();
>cin.get ();
>return 0;

These are all unnecessary.

All suggestions included:

#include <iostream>

int main()
{
  int a, b, result;

  std::cout<<"Enter two numbers: ";
  std::cin>> a >> b;

  result = a + b;

  std::cout<< result <<"\nYour result is "<< (result % 2 ? "odd" : "even") <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>uhhm.. if i use this, its clear that i asked someone to helped me..
Good. Then learn from it instead of blindly copying my code. All of the necessities are there if you take the time to understand what was done and why.

Narue 5,707 Bad Cop Team Colleague

At the risk of confusing you, I'll offer a more robust solution than you'd normally be given. Since it's more complex, I'll happily explain anything you don't understand:

#include <stdio.h>
#include <string.h>

int continue_working ( const char *msg, const char *true_case )
{
  char buffer[BUFSIZ];

  /*
    Don't do printf(msg);
    It invites malicious input strings
  */
  printf ( "%s", msg );

  /* Force a flush because '\n' wasn't printed */
  fflush ( stdout );

  /*
    Using line input to avoid both a dirty stream
    and ugly/dubious stdin flushing techniques
  */
  if ( fgets ( buffer, sizeof buffer, stdin ) == NULL ) {
    /*
      You can get clever here if you want, I
      just kept it simple at fgets fails means stop working
    */
    return 0;
  }

  /* Remove '\n' from the buffer if it's there */
  buffer[strcspn ( buffer, "\n" )] = '\0';

  return strcmp ( buffer, true_case ) == 0;
}

int main ( void )
{
  /*
    Loop forever
    while ( 1 ) may not give a clean compile
  */
  for ( ; ; ) {
    /* Replace this line with your program's real work */
    printf ( "Doing work!\nDone.\n" );
    
    if ( !continue_working ( "Keep working? (y/n): ", "y" ) )
      break;
  }

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

>what they do have is an unsigned char class to
>convert ints/doubles/floats to binary/bytes.

You're thinking of type punning, I believe. Tricky business that stuff, not usually a good idea in C++.

>if you have an unsigned char*, you can't actually get
>the size of the number of bytes this represents

Obviously because it's a pointer, not an array of bytes. But you can use sizeof on the original object or the type of the original object to get the number of bytes.

>vector<unsigned char> but cant figure out how to
>copy a float into the vector to get each byte

It sounds like you're on the express train to undefinedbehaviorville with this conversion. But ask and ye shall receive:

double d = 123.456;
unsigned char *p = (unsigned char*)&d;
std::vector<unsigned char> v ( p, p + sizeof d );
Narue 5,707 Bad Cop Team Colleague

>Is it required that after doing my engineering in I.T. department
>I need to professionalize myself in one particular language?

Heh, "professionalize"? :) Anyway, if you're going to be using a language on the job as a programmer, it's best to learn it well enough such that you're competent. Otherwise, programming skills are secondary (or even tertiary). For example, I'd expect a system admin to know basic SQL and some scripting, but that's about it in terms of requirements. The answer to your question really depends on what jobs you want to apply for.

>what are the languages that most companies prefer from the applying candidates?
Reading the classifieds, I'd say you need to be an expert of every language under the sun (including the ones that haven't been invented yet), on every platform since Babbage's analytical engine, and have 10+ years of experience with every buzzword the company can think of. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

>After the applicant passing some test, do you ever try to throw
>some tricky question, to see if he can answer them?

I try to keep it practical. If I ask a tricky question, it's probably because we've encountered a problem like that before on the job. In those cases I'm looking more for a problem solving methodology than the correct answer.

>Also is your applicant C, C++ or does not really matter?
C, C++, C++/CLI, C#, VB.NET, VB6, Java, Perl, Python, Pascal, and Delphi are the most common languages I use for interviews. Occasionally I get grads who like one of the LISPs. I expect extensive knowledge of the language they'd be using on the job, of course, but a lot of the questions are general and I let them choose which language to use. Sometimes I give problems where an appropriate choice of language is what I'm looking for. :)

>Have you got any samples you'd be willing to post?
One example is the naive atoi implementation that breaks on INT_MAX. It's good for finding and fixing edge case bugs, and a surprisingly small number of candidates are familiar with it. Another good one to see if the candidate keeps with the times is the binary search bug. Something short and sweet but with a non-obvious problem is ideal. That way we can go through a few of them quickly.

Dave Sinkula commented: Danke. +0
Narue 5,707 Bad Cop Team Colleague

>A test just shows that you know definition( in a sense).
I think a good test is more than multiple choice. The test questions should force you to think about a problem and write out a short essay or code answer. Unfortunately, multiple choice questions are easier to write and easier to grade with a computer, so that's how online tests and up being written.

tux4life commented: s/and/end ? :P +7
Narue 5,707 Bad Cop Team Colleague

>Is it true that the finally block doesn´t execute either ?
The finally block always executes, whether an exception was thrown or not.

Narue 5,707 Bad Cop Team Colleague

He asked for comments and I commented. I'm not going to blow sunshine up his ass just to make him feel good. Honesty and objectivity are far more useful than lies and fear of offending people.

>you criticize people like your a super genius...
I criticize where appropriate.

>your too full of yourself...
I don't worry about false modesty just to make people feel better about themselves.

>you think your so smart?
I think I'm experienced enough, having conducted many interviews, to accurately comment on the OP's answers.

Narue 5,707 Bad Cop Team Colleague

Q: what are the different stages in SDLC?
Me: Requirement Analysis -> Design -> coding -> Testing -> Implementation and Maintenance

Canned answer to a vague question, not promising at all. I'd expect you to dig for more details before coming up with an answer. For example, which methodology am I talking about? Interviewers will often ask questions that are meant to prompt a series of questions from a good candidate.

Q: what are the advantages of C++ over C?
Me: C++ is an Object Oriented Programming Language while C is a Procedure oriented language
Q: Other than that?
Me: Sorry madam, I don’t know.

Superficial answer, no depth of understanding exhibited. The "advantage" implied by the answer is not really an advantage. All in all a very poor answer. Your inability to come up with anything else suggests that you have only a rudimentary knowledge of those languages.

Q: what are the advantages of Using C?
Me: Don’t know madam

While "I don't know" is a promising answer in and of itself, complete failure to know even the most basic answer to this question is not a good sign. Assuming basic knowledge of C is important for getting the job, I'd have crossed you off my list by now.

Q: what are the advantages of .NET framework?
Me: Robustness, security, RAD, Interoperability….

Canned answer, lots of empty calories, and no real display of understanding. Not a …

Salem commented: Seems about right to me :) +0
Rashakil Fol commented: A++ would read again, and did +0
Narue 5,707 Bad Cop Team Colleague

>I see the "new" operator is very different from java one, is it right?
Not especially. The Java new expression creates an object of the specified type, calls the specified constructor, and returns a reference to the object. This is pretty much identical to C++ where a new expression creates an object of the specified type, calls the specified constructor, and returns a pointer to the object. The only real difference (at the superficial level you should be comparing C++ and Java) is you can do more with a C++ pointer than a Java reference.

chaienbungbu commented: Thank for your info. +1
Narue 5,707 Bad Cop Team Colleague

>But what is the difference here? (&FileParser::saveElement) is parsed as the address of a class member. The parentheses are redundant in this case. &(FileParser::saveElement) is parsed as trying to access a static member and then take the address of it. saveElement isn't a static member, and if it were a static member, you wouldn't be able to use it as the address for a pointer to a member. End result: the compiler pukes on your code.

Narue 5,707 Bad Cop Team Colleague

>yes couldnt find any
Either you're lying or you're incompetent. I'm suddenly less interested in helping you.

Narue 5,707 Bad Cop Team Colleague

>and the fact that well, coding in it looks so beautiful.
"Ooh, shiny! ...what was I coding again?"

Narue 5,707 Bad Cop Team Colleague

>i dont really understand about c++.i havent got any attempt
So let me get this straight. You've been taking a C++ class and reached the term project, but you're still so clueless that you can't even write the most rudimentary code to prove that you've made an attempt?

Sorry dude, but you deserve exactly what you're going to get: a failing grade for a slacker who doesn't care enough to pay attention in class.

Narue 5,707 Bad Cop Team Colleague

>how can you explain the fact that you can fill the array this way?
The members I didn't explicitly initialize get default initialized to 0. In the case of a pointer, zero initialization is a null pointer.

>Do you think that can be done with this method?
I want to say yes, but your question is vague enough that I can't be sure. When you say you want to get a size, do you mean a size of the array (such as a dynamic array)?

Narue 5,707 Bad Cop Team Colleague

I get the impression that you're looking for a variant type. C isn't good at that, so you might consider something more along these lines:

#include <stdio.h>

#define TYPEA 0
#define TYPEB 1

struct my_struct {
  int type;
  void *data;
};

struct a {
  double x;
};

struct b {
  int x;
};

int main ( void )
{
  struct a foo = { 1.23 };
  struct b bar = { 123 };
  struct my_struct my_array[] = {
    { TYPEA },
    { TYPEB }
  };

  my_array[TYPEA].data = &foo;
  my_array[TYPEB].data = &bar;

  printf ( "TYPEA: %f\nTYPEB: %d\n", 
    ( (struct a*)my_array[TYPEA].data )->x,
    ( (struct b*)my_array[TYPEB].data )->x );

  return 0;
}

A pointer to void is the generic type in C, but it can be awkward to use in some cases.

Narue 5,707 Bad Cop Team Colleague

>Can you help me please ?
Not until you show us your attempt and prove that you're not a cheating leech.

NicAx64 commented: YOU ARE A VERY CRUVAL TEACHER WITHOUT ANY SENSE OF HUMOR. +1
Narue 5,707 Bad Cop Team Colleague

>One might say it is random,another might say it isn't.
One might also say that in trying to sound intelligent, you missed the point completely.

Narue 5,707 Bad Cop Team Colleague

>Or loop through the 'char' and use the num = (num * 10) + char process.
Nine times out of ten, this algorithm breaks on edge cases. Unless it's a homework problem, such a manual process isn't recommended when there are better alternatives like std::stringstream.

>Use something like this
Manually removing the commas smells kludgy. You can easily imbue the stringstream with a suitable locale and all of that work will be done by the library:

#include <iostream>
#include <locale>
#include <sstream>
#include <string>
#include <typeinfo>

template <typename T>
T parse ( const std::string& s, std::locale loc = std::locale ( "C" ) )
{
  std::istringstream in ( s );
  T result;

  in.imbue ( loc );

  if ( !( in>> result ) || !in.eof() ) {
    std::ostringstream err;

    err<<"Could not convert to type "<< typeid ( T ).name()
       <<" at "<< in.rdbuf();

    throw std::invalid_argument ( err.str() );
  }

  return result;
}

int main()
{
  try {
    const char *p = "312,000";

    // This is the important part. The "C" locale expects
    // no digit separators, but the "" locale uses local
    // area conventions (commas in my case)
    double d = parse<double> ( p, std::locale ( "" ) );

    std::cout<<"The value is "<< d <<'\n';
  } catch ( std::invalid_argument& ex ) {
    std::cout<<"Invalid floating-point value: "<< ex.what() <<'\n';
  }
}
Narue 5,707 Bad Cop Team Colleague

>Can anyone tell me why?
Your pointer is uninitialized. It's not a pointer to infinite memory, it's an invalid pointer. Expect crashes and unpredictable results, because that's what happens with undefined behavior.

>I wanted to take a line input of infinite length.
It's not that easy. You need to read into a single character or a block of characters, resize your buffer, and then copy into it until input is complete. For example:

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

#define AGETS_PARTIAL 0x8F5

/*
  Read characters into a result string until '\n', EOF, or error
    * NULL is returned if no characters were stored,
      otherwise the current string is returned
    * The '\n' character is not retained
  The result string is dynamically allocated and must be freed
  errno is set to AGETS_PARTIAL if a partial string is returned
*/
char *agets ( FILE *in )
{
  char *buf = NULL;    /* Destination buffer */
  size_t capacity = 0; /* Current buffer capacity */
  size_t size = 0;     /* Current number of characters in the buffer */

  for ( ; ; ) {
    int ch;

    if ( size == capacity ) {
#define CHUNK_SIZE 8
      /* Make space for the null character, but don't include it in capacity */
      char *save = realloc ( buf, ( capacity += CHUNK_SIZE ) + 1 );
#undef CHUNK_SIZE

      if ( save == NULL ) {
        if ( buf != NULL )
          errno = AGETS_PARTIAL;

        break;
      }

      buf = save;
    }

    /* …
tux4life commented: Nice code :) +6
Narue 5,707 Bad Cop Team Colleague

>I can reconsider my personal opinion on the big G policy if they will close to
>Chinese government request also if this mean close the business in China.

You should send them an email. I'm sure that changing your personal opinion is a huge incentive for Google.

Narue 5,707 Bad Cop Team Colleague

>let user start with x.
>the series is x,x+12,x+15,x-4,...

How very droll. Though it frightens me that you might actually be serious.

Narue 5,707 Bad Cop Team Colleague

>Use Dev-C++ cos its best for installing new libs.
You'd be wise to avoid stating opinions as if they were fact.