deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm, seems awkward. I'd probably start by trying something like this:

private bool _addingItem = false;

private void comboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
    var ctrl = sender as ComboBox;

    if (ctrl.SelectedItem.ToString() == "Add")
    {
        _addingItem = true;
        ctrl.Focus();
    }
}

private void comboBox_KeyDown(object sender, KeyEventArgs e)
{
    if (!_addingItem)
    {
        return;
    }

    var ctrl = sender as ComboBox;

    if (e.KeyCode == Keys.Enter)
    {
        if (!ctrl.Items.Contains(ctrl.Text))
        {
            ctrl.Items.Add(ctrl.Text);
            ctrl.Invalidate();
            e.Handled = true;
        }
    }
}

private void comboBox_Leave(object sender, EventArgs e)
{
    _addingItem = false;
}

Obviously there are plenty of use cases to consider, but for the basic functionality the above seems like a reasonable start.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And what about the files themselves? Specifically the type and size.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How do I find out the path.

Google for getcwd() and chdir().

Also, is there any way to read integers or float from a file like wav file.

Yes, but if you're reading a binary file with a specific format you'll need to conform to that format when reading the file. Look up the specification for the format here. Often it's not as simple as just reading a float or any integer, you need to fully parse the file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How do I know what is my current directory and how should I change it?

What compiler and OS are you using? There's not a standard solution, but there are a few fairly consistent rules:

  1. When running from the command line, whatever directory you're in at the point of program invokation is the current working directory. Note that you can call a program from another directory by specifying its full or relative path.

  2. When running from an IDE, the current working directory is either the location of the executable file in your build directories or a nested debug directory.

  3. When running from a GUI (ie. clicking on its icon to run a program), the current working directory could be either the directory where the executable file resides or a configured default such as the user's home directory or documents folder.

It's best to ensure that you're in the directory you want, but as mentioned there's no standard way to do that. However, most compilers will support some form of the getcwd() and chdir() functions that retrieve and set the current working directory.

Also, what do you mean by "error return code for the library input function". Does that mean the macro EOF??

The EOF macro is included, but not the only thing I meant. fgets() returns NULL as a failure code, not EOF, so you need to account for variances like that and also check feof() if there's a possibility that the error could be …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I was wondering how the compiler searches for a file using just the name of the particular file.

Typically, a relative path will behave as if the current working directory were prepended. For example, on Windows "file.txt" would be treated as if it were "%cd%\file.txt".

If I have loaded a binary file how am I supposed to know that at what position the file is ended. For text files the ASCII value of 26 signified end of file, how do we figure out the end point of a binary file?

In all cases (text and binary) the standard library will tell you when end of file was reached. This usually means the error return code for the library input function, and feof() can be used to differentiate between end of file and an actual stream error.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you getting this problem in the quick reply box or on edit? What version of Firefox? What OS and version of the OS? Do you have any notable add-ons installed? If you view page source are the input tags present and just not rendered, or are they missing entirely?

It's broken again. I've completely cleared the cache and still there are no text entry/browse buttons.

It's not really broken again because it was never really fixed. I been unable to reproduce this error for nearly a year, and fixing something I can't reproduce is somewhat difficult.

I tried attaching the files via IE. While the text fields and buttons rendered, and I was able to browse and select the two files, neither of the files actually got attached.

Can you link to the post you were attaching files to? Also, what type and size of file are we talking about?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the difference between CDbl() and Convert.ToDouble().

CDbl() is a little smarter by default in that it takes different numbering styles into consideration. You can get a similar effect with Double.Parse() and a formatter of NumberStyles.Any, with the understanding that the extra work has a runtime cost compared to Convert.ToDouble(), where the default behavior uses Double.Parse() with the less thorough NumberStyles.Float and NumberStyles.AllowThousands (if I recall correctly, of course. AllowThousands may not be default).

Ultimately it comes down to whether you want support for currency formatting, slightly more concise syntax, and don't mind depending on the Microsoft.VisualBasic assembly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The conversion between a string and double isn't implicit. Try calling Convert.ToDouble().

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Imports Google.RTFM

Granted, I did make an assumption that you were writing an ASP.NET page. But it's trivial to search MSDN for HttpContext and see that you import System.Web.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster
HttpContext.Current.Request.Url
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In lines 11 and 15 you're assigning to $count, not comparing it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why should censorship be that important for users under 13? They begin to start cursing at each other in elementary...

Such a cynical perspective...

People should be able to write a coherent sentence without resorting to foul language.

The problem is that "foul language" is a moving target depending on who you ask. Case in point, you think ass isn't foul while others most certainly would.

How can anyone proof someone's age?

We obviously can't stop people from lying about their age, but not having the age confirmation leaves us legally vulnerable. I've personally banned more than a few people for N years until they reach 13 because they accidentally let their real age slip.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wanted to make sure it would work and not slow things down

There's never a guarantee, even if you know what you're doing. Developers historically have been notoriously bad at guessing where performance bottlenecks would be.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how difficult would it be to have a .lib and a .dll file so I can work with both Linux/Unix and Windows?

You'd have two builds for the two systems. Whether the actual code that gets built needs to be ported to support the different systems depends on what you're doing. That also dictates how hard it is, but it could be as simple as just rebuilding with a different target (if the code is 100% standard C++, which is portable) to anywhere as hard as rewriting the whole thing (if you use a lot of platform dependent code).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

GIMP is the open source equivalent to Photoshop, but don't expect it to be as user friendly. I'm not familiar with the latest HTML packages. try searching Google. I use NetBeans if you're interested, though it's more of an IDE for PHP than a website designer like Dreamweaver.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I was thinking of creating a class that stores all relevant data but I dont know if that would make it less efficient

Here's a novel idea: try it and see what happens. Then you'll know after teaching yourself through experience. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My question is what [100] in the first line of the Pseudocode stands for?

It's the size of an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That has nothing to do with character sets. You can use ASCII exclusively and still confuse a user in Germany by displaying 1,234.56 instead of 1.234,56.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There's a space at the end of the format string in scanf(), remove it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

it keep showing me only 1 movie count even there are more!!

Debug the code and figure out what's wrong then. I don't have your file to test with, so I can only go on what you've provided in this thread.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The filtered words list can be a little funky. IIRC, the weirdness comes from Dani's analysis of words that are most likely to be used in an insulting manner towards another person.

Given that we already require members to be at least 13 years of age, I'd prefer no automatic censorship, but that's not my call. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Anyone know how to do it that way?

Unless you feel like dropping down to inline assembly, the best (only) solution is to verify that the operation won't overflow before you perform it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, I opened on in an other file, and an otehr class. Do I need to open one in this class aswell?

I'd keep connections local to the class that uses them, but that's because I'm stupid and need the extra help. ;) Provided you open the connection before making calls to mysql_query(), it should be okay, but you do need to consider order of operations since it's not super explicit.

Your query is simple, but it still couldn't hurt to echo the final string that gets passed to mysql_query() and run it manually from MySQL just to be sure it works the way you think it works.

Also, include error checking with mysql_error() for more details about the problem:

$result = mysql_query($query);

if (!$result) {
    die('Error: ' . mysql_error());
}

...
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your query failed for some reason. I notice you didn't provide a connection as the second argument to mysql_query(), have you opened a connection to the database already?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My random number implementations in this program are not ment to be cryptographically secure.

I wasn't talking about being cryptographically secure. In fact, being cryptographically secure when all you need is something a user would recognize as "random" would be unnecessarily inefficient.

As an example of using the low order bits to generate a random sequence, there have been implementations where rand() % 2 would produce a range of [0,1,0,1,0,1,0,1...] (just alternating 0 and 1). This is a highly predictable and nobody would call it random. The low order bits of the result were disturbingly non-random, so using modulo to extract just those bits was a poor solution.

I would definitely pass and check the buffer size to the function. The dtoa function as given could easily overflow the buffer and not know it.

That code was taken from one of my libraries where I control the buffer, so it's guaranteed to be large enough for any double value. I don't think overflow is a huge issue when the string representation is tightly bound to an upper limit, and there was little point in adding it for this example as it distracts from the topic, but as a general library you're correct that it should account for being called by a moron. ;)

Also, I am using char (ASCII) and not wchar (Unicode). I do not plan on changing this, although the number adjustments could be a good idea.

I didn't assume otherwise in …

tux4life commented: Nothing would prevent a moron to pass a wrong buffer size though :D +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please help? What am I doing wrong?

You're not closing binaryNum as a string, so garbage gets copied into immeStr. Change the definition to this for a simple solution:

char binaryNum[bit+1] = {0};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How similar are they?

They share general sentence structure. I haven't delved too far into Spanish grammar, but it seems similar enough that I'd probably have far fewer issues making the jump than from English.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your Spanish experience will come in handy when/if you decide to tackle Japanese.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

English and a bit of Japanese.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the type is unknown, try using Object^. Provided you're working with CLI types, they're all derived from Object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hey tell me "system()" is in which header file?

#include <cstdlib>
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wrote code to do this calculation but I can't find it, so I'll leave implementation as "an exercise for the reader". Have fun!

Piece of cake considering I've already written this for my standard C library implementation. Here's the meat of it, slightly modified:

#include <stdio.h>

#define _LEAP_YEAR(year)  (((year) > 0) && !((year) % 4) && (((year) % 100) || !((year) % 400)))
#define _LEAP_COUNT(year) ((((year) - 1) / 4) - (((year) - 1) / 100) + (((year) - 1) / 400))

const int yeardays[2][13] = {
    { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 },
    { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
};

const int monthdays[2][13] = {
    { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
    { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};

int weekday(int year, int month, int day)
{
    int ydays, mdays, base_dow;

    /* Correct out of range months by shifting them into range (in the same year) */
    month = (month < 1) ? 1 : month;
    month = (month > 12) ? 12 : month;

    mdays = monthdays[_LEAP_YEAR(year)][month - 1];

    /* Correct out of range days by shifting them into range (in the same month) */
    day = (day < 1) ? 1 : day;
    day = (day > mdays) ? mdays : day;

    /* Find the number of days up to the requested date */
    ydays = yeardays[_LEAP_YEAR(year)][month - 1] + day;

    /* Find the day of the week for January 1st */
    base_dow = (year * 365 + _LEAP_COUNT(year)) % 7;

    return (base_dow + ydays) % 7;
}

Dates are tricky though, and this only works within the confines of ISO C library requirements.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i guess ubuntu does not like finding rogue semicolons in the code for you.

This is a perfectly legal loop:

for (i = 0; i < 20; i++)
    ;

The compiler shouldn't diagnose it as an error, but can (and likely will) optimize it into this:

i = 20;

By the way, Ubuntu is an operating system, not a compiler. You probably mean GCC.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but if my txt file is wrriten like this:

That's fine then.

its stiil dont do the math

That file works for me (assuming the -->rented and -->not rented parts are exposition added by you for the post and not actually in the file. If they're in the file then you need to remove them from the stream:

#include <stdio.h>

int main(void)
{
    struct rental {
        char name[20];
        int year;
        int inout;
    } movies[20];

    FILE *in = fopen("test.txt", "r");

    if (in) {
        size_t i, n, sum = 0;
        int ch;

        for (n = 0; n < 20; n++) {
            if (fscanf(in, "%19[^\n] %d %d ", movies[n].name, &movies[n].year, &movies[n].inout) != 3) {
                break;
            }

            while ((ch = getc(in)) != '\n' && ch != EOF)
                ;
        }

        fclose(in);

        for (i = 0; i < n; i++) {
            sum += movies[i].inout;
        }

        printf("Available movie count: %d\n", sum);
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I would ask a few questions:

  1. "31 32 33..... til end of file". What does end of file mean here? Are you reading input from a file? Are you just printing numbers until the user tells you to stop? The behavior isn't obvious here, so writing code for it is impossible.

  2. How are negative values handled? Is it just assumed that all numbers are positive?

  3. What about things like ",," or ",-,"? Are they errors or need to be included in the logic?

Excluding the part that's completely ambiguous, and assuming only positive numbers, the rest of the logic is straightforward. However, dong it right doesn't result in teeny tiny code unless you're trying to obfuscate:

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

void print_range(int start, int stop)
{
    if (start > stop) {
        /* Print a decreasing range */
        while (start >= stop) {
            printf("%d ", start--);
        }
    }
    else {
        /* Print an increasing range */
        while (start <= stop) {
            printf("%d ", start++);
        }
    }
}

int main(void)
{
    int next; /* Represents the next character from the stream */

    do {
        char buf[BUFSIZ] = {0};

        /* Look for non-negative numbers */
        int rc = scanf("%[0123456789]", buf);
        int start = atoi(buf);

        next = getchar();

        if (next == '-') {
            int stop;

            if (scanf("%d", &stop) != 1) {
                /* Placeholder for ranges with an implicit end. Just error for now */
                fprintf(stderr, "Invalid  format: Missing range end\n");
                break;
            }

            print_range(start, stop);
            putchar('\n');

            next = getchar();
        }
        else if (next …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

priceperbushel is a double, not an int. Actually, I'd recommend using double everywhere you use float too. You also have a rogue semicolon in getProfit() that's breaking the loop.

Consider this:

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

double getProfit(double bushels[], double price);
double getCosts(double acres[], double totalAcres, double cost);

int main()
{
    double acres [20];
    double bushels [20];
    double cost;
    double pricePerBushel;
    double totalAcres = 0;
    char choice;
    int count = 0;

    for(count = 0; count < 20; count++)
    {
        acres[count] = 0;
        bushels[count] = 0;
    }

    count = 0;

    printf("\nwould you like to add anouther field:");
    scanf("%c", &choice);
    getchar();

    while(choice != 'n')
    {
        printf("\nEnter the number of acres:");
        scanf("%lf", &acres[count]);
        getchar();
        totalAcres += acres[count];

        printf("\nEnter the number of bushels:");
        scanf("%lf", &bushels[count]);
        getchar();

        printf("\nwould you like to add anouther field:");
        scanf("%c", &choice);
        getchar();

        if(count == 19)
        {
            printf("\nyou cannot add any more fields");
            choice = 'n';
        }
        count++;
    }   // end of loop

    printf("\nenter total bills:");
    scanf("%lf",&cost);
    cost = getCosts(acres, totalAcres, cost );

    printf("\nenter the price per bushel:");
    scanf("%lf", &pricePerBushel);
    getProfit(bushels, pricePerBushel);

    int i = 0;

    for(i = 0; i < count; i++)
    {
        bushels[i] = bushels[i]-(acres[i]*cost);
        printf("the profit for the field #%d is %f \n", i,bushels[i]);
    }

    return 0;
}

double getCosts(double acres[], double totalAcres, double cost)
{
    int i = 0;

    cost= cost/totalAcres;

    return cost;
}

double getProfit(double bushels[], double price)
{
    double temp = 0;
    int i = 0;
    for(i = 0; i < 20; i++)
    {
        temp = bushels[i];
        temp = temp * price;
        bushels[i] = temp;
    }

    return …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon can you please explain the printf statement?

This is the point where I'll suggest that you RTFM, because format strings are clearly and completely described. But, I'll also explain it.

The %g specifier selects the behavior of either the %f or %e specifier (that's fixed or scientific format, respectively), depending on the actual value being printed. By default, if the exponent in your value exceeds 6 or -4, %g uses scientific format rather than fixed format. Trailing zeros are omitted, which is behavior you want (%f doesn't provide this).

When you provide a precision to the specifier (a dot followed by a numeric value), %g treats that as a maximum number of significant digits, which means both whole number digits and precision digits. For example, the value 123.456 has six significant digits. IF you try to print it with printf("%.4g", 123.456), you'll get 123.4 as output.

The numeric value in the precision can be a placeholder for an argument rather than a literal value in the string, that's what the asterisk does. It says "take the next argument to printf() and use that value as the precision". Another way of writing the example above using a placeholder would be printf("%.*g", 4, 123.456).

All in all, what my example does is calculate the number of digits in the whole value, then adds 8 to this (where 8 corresponds to the number of precision digits you want), then uses that value as the significant digits for the %g specifier. …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It comes to my mind that I'd rather use some virtual machine like virtualbox for Linux and then install the the windows os and .net packages. I think that is the best solution to run the executable file in c#. What do you think?..

That doesn't strike me as something your client will go for, since the requirement was to run your program on CentOS. You could bring it up as an option, certainly, but don't be surprised if they poo-poo the idea.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Haha we both typed almost identical instructions at the same time!

Great minds. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pay special attention to the "precision" and "field width" specs above.

No disrespect, but unless I'm misreading your post (in which case I apologise) you should follow your own advice. ;) The %f specifier doesn't remove trailing zeros when the precision exceeds the value, and the precision on the %g specifier affects significant digits rather than digits after the radix. So while %g can be used to get the correct behavior, that's only after doing introspection on the value to determine how many whole digits are present:

#include <stdio.h>
#include <math.h>

int main(void)
{
    double a = 1234.567891234;

    // Quick and dirty digit count
    int digits = log10((double)(int)a) + 1;

    printf("%.*g\n", 8 + digits, a);

    return 0;
}
rubberman commented: Good point - haven't had to deal with this cruft in 20 years! :-) +11
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd like to know if I'm doing the allocation of memory from data to new_data correctly

Looks like it, at least if set is implemented the way I'd implement it using that interface.

why new_data only has one value since the memory of data was copied before to new_data.

new_data is a pointer to a single integer, why would there be more than one value? Your question suggests that my assumptions about how your set is implemented are wrong and you're potentially leaking memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's no longer embedded in the post, but the file is still attached. You can remove it entirely through the same process that you added it:

  1. Edit the post
  2. Click the Files button
  3. Click the 'Delete' link next to the attached image (where the embed buttons are)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Off the top of my head, I'm going to say that it's not possible to mix and match %f (which supports a precision) and %g (which has a zero removal rule). You'd need to use a less direct solution, such as sprintf() followed by a right trim of zeros.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

*bushels[i] = *(bushels[i]*price);

The indexing operator already dereferences the pointer, what you're trying to do is dereference a float value, which clearly won't work. Try this instead:

bushels[i] = bushels[i] * price;

Or using the compound operator:

bushels[i] *= price;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wow, just...wow. See that word in your code that says readonly? Make it go away.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A readonly field `SearchEmp.name' cannot be assigned to

So...what does that tell you? It's not like the error is ambiguous or unclear. SearchEmp.name is defined as readonly, yet you try to assign to it as if it were not readonly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Also please tell me about these error.

You forgot to list the errors, and your title for this thread is uninformative.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yup, it's pretty simple:

I didn't suggest otherwise. It's a smidge more complicated because we'd still want to support local avatars, but I'd almost call such a feature trivial to implement...almost. ;)

My concern had more to do with whether supporting Gravatar would be both sufficiently beneficial as well as likely to continue to be beneficial going forward.

cereal commented: agree :) +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For starters, movie_rent is neither an object nor an array, it's a type. The object declaration would be more correct like this:

struct {
    char name[20];
    char year[20];
    int inout[20];
} movie_rent[20];

But that doesn't fix your syntax issues because you can't seem to decide if movie_rent is an array and inout is an int (circa line 30 and 34):

movie_rent[i].inout=0;

...

fscanf(myfile,"%c %c %d[^\n]", movie_rent[i].name, movie_rent[i].year,movie_rent[i].inout );

Or movie_rent is a single structure instance and inout is an array of int (line 39):

sum=sum+movie_rent.inout[i];

I suspect you want an array of movies:

#include <stdio.h>

int main(void)
{
    struct rental {
        char name[20];
        int year;
        int inout;
    } movies[20];

    FILE *in = fopen("mov.txt", "r");

    if (in) {
        size_t i, n, sum = 0;

        for (n = 0; n < 20; n++) {
            if (fscanf(in, "%19s %d %d", movies[n].name, movies[n].year, movies[n].inout) != 3) {
                break;
            }
        }

        fclose(in);

        for (i = 0; i < n; i++) {
            sum += movies[i].inout;
        }

        printf("Available movie count: %d\n", sum);
    }

    return 0;
}

This should work for movies that have a single word name (it's untested, so I reserve the right to have made stupid errors/typos), but for multiword names you're SOL using the %s specifier and need to figure out something different. I'd suggest flipping the format around so that the name is last, then doing this:

if (fscanf(in, "%d %d %19[^\n]", movies[n].name, movies[n].year, movies[n].inout) != 3) {
    break;
}

That way you …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let's start with your assumption about the formatting of a numeric value, which isn't safe these days. Consider the following function that's designed to be locale-friendly for the same task:

#include <ctype.h>
#include <locale.h>
#include <math.h>
#include <string.h>

char *dtoa(char buf[], double value, int precision, int show_sign)
{
    char *grouping = localeconv()->grouping;   /* Locale-specific grouping count/order */
    int group_size = *grouping;                /* Current working group total size */
    int group_len = 0;                         /* Current working group processed size */
    double ipart;                              /* Integral half of the value */
    double fpart = modf(fabs(value), &ipart);  /* Fractional half of the value */
    size_t last = 0;

    /* Set and skip any explicit sign */
    if (value < 0 || show_sign) {
        buf[last++] = (value < 0) ? '-' : '+';
    }

    /* Build the locale-friendly integer part */
    for (; fabs(ipart) > 1; ipart /= 10) {
        if (group_size && group_len++ == group_size) {
            /*
                The current working group has been completed. Apply
                a group separator and move to the next locale-specified 
                grouping. Repeat the last valid grouping if the locale
                doesn't specify any further groupings.
            */
            buf[last++] = *localeconv()->thousands_sep;

            if (*grouping && *++grouping) {
                group_size = *grouping;
            }

            /* Reset the group to 1 because a digit is still being processed */
            group_len = 1;
        }

        buf[last++] = (char)(fmod(ipart, 10) + '0');
    }

    if (last == 0 || (last == 1 && !isdigit(buf[0]))) {
        /* There weren't any integer part digits, force to 0 */
        buf[last++] = (char)((int)fmod(ipart, 10) + …