deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm, does this mean that Walt is the new Narue? Before it was always Narue's sharp tongue that everyone feared. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I actually had planned on writing a sort tonight. Well, i'll think of something else to add.

How about a stable sort? :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

as i am taking result as double which always a approximate value so multiplying this (result*result) will give me the correct output ?

Your concern is justified. To be strictly correct your equality check should add a fudge factor:

result *= result;

if (fabs(result - number) < FUDGE)
    puts("The integer is a perfect square");
else
    puts("The integer is not a perfect square");

FUDGE would be defined as the precision to which you consider numbers to be equal. So something like const double FUDGE = 0.0001 for a few digits of precision.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

oops! first time you got angry! :(

Often a curt reply can be extremely effective.

If you manage to actually make me angry, much less angry enough to post without deep consideration behind my words, you'll be in a very small and elite group that I won't need more than two hands to count and will remember forever. In other words, ain't gonna happen. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You realize that by calling out Walt, you've guaranteed that he'll blast you for not using any formatting and for unnecessarily living in the 90s with Turbo C++, right?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Start by adding age since that's easier due to lack of string handling requirements. Add something like int age; to the struct definition and then everywhere the other "attributes" are used, add an equivalent line for age.

Since your Google document is blank and you neglected to post any code, I can't really help you more than that.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So that the additions and suggestions aren't lost to github, here are two more public functions and one private helper. The first is a generic swap, since the storage for the darray may be confusing and awkward to work with directly. The second is a heapsort implementation:

static bool do_heap(darray *p, size_t i, size_t n, int (*cmp)(const void*, const void*));

/*
    @description:
        Swaps two elements in the darray pointed to by p. If the
        swap could not be completed, false is returned. Otherwise
        true is returned.
*/
extern bool darray_swap(darray *p, size_t pos1, size_t pos2)
{
    if (pos1 >= p->capacity || pos2 >= p->capacity)
        return false; /* Out of range index */
    else {
#if __STDC_VERSION__ >= 199901L

        /*
            VLAs can be risky due to the runtime size not under programmer
            control. So if the size is greater than a threshold, use
            dynamic allocation. That should rarely happen here, if ever, 
            because the item_size is assumed to be the number of bytes 
            in an object.
        */
#define VLA_LIMIT 1024
        unsigned char temp_base[p->item_size < VLA_LIMIT ? p->item_size : 1];
        bool dynamic_temp = false;
        void *temp = temp_base;

        if (p->item_size >= VLA_LIMIT) {
            temp = malloc(p->item_size);
            dynamic_temp = true;
        }
#undef VLA_LIMIT

#else /* __STDC_VERSION__ */

        /*
            Prior to C99 we can't take advantage of a stack-based
            array with a runtime size. At least we can't without using
            something nonportable like alloca(). To keep the library
            portable, malloc() is used, despite slowness.
        */
        void *temp = malloc(p->item_size);
        bool dynamic_temp = false; …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your push() member function is broken. In the case where top isn't NULL, you have three lines:

top -> next = temp;
top = temp;
top -> next = NULL;

The first thing to notice is that top->next is always reset to NULL, always. That line is a bug and should be removed. You're also pushing in the wrong direction. The top of the stack is the most recently pushed item, so you need to set temp->next to top rather than top->next to temp:

temp -> next = top;
top = temp;

The display member function also has an off by one error wherein you don't print the oldest node in the stack. Your condition should check temp against NULL rather than temp->next:

while(temp != NULL)
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

From the documentation it seems CSound doesn't support fenced comments. So you can't do what you want, you'll need to reorganize things so that the comment is either the last thing on the line or on a line by itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

ItemList list();

This doesn't do what you think it does. Due to a parsing ambiguity, the resolution of the above declares a function called list that takes no arguments and returns an object of type ItemList. It doesn't create a new object called list with a type of ItemList, to do that you need to remove the parens:

ItemList list; // Create a new ItemList called list

Confused yet? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why would you want an OCX when there are .NET barcode libraries? Anyway, are you looking to read or write barcodes? Do you just need 1D symbologies or are 2D important too? Not all barcode libraries support the same stuff, so you'll need to do a little research. Limiting yourself to free options is also going to be troublesome because the best and most fully featured libraries aren't free.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Tonari no Kaibutsu-kun and Suki-tte Ii na yo are all I need to call this season a home run. Today is a good day for otaku deceptikon-kun. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is by design.

I wouldn't say it's by design, but it certainly falls out of how Markdown and our code detection algorithm work. The two conspire (possibly unintentionally) to make it impossible to have quoted code tags.

Markdown can handle quoted code tags with a little manual tweaking of the autoquote feature, but our code detection algorithm pukes on it because of the leading quote starter on the line.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That sounds familiar. Please try clearing your browser's cache and see if that corrects the problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, one obvious problem is that your factorial function may return a double, but it uses an int internally to calculate the factorial. Therefore you're still limited to the range of a signed integer.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nice. Good idea to put it in public version control. :)

Two suggestions though:

  1. Since darray_compare_bytes() is basically reinventing memcmp(), why not just use memcmp() to begin with?
  2. The function comment for darray_compare_bytes() is a copy paste of darray_search(), you forgot to change it. ;)

It's fun seeing how different people write code that's functionally the same. For example, I'd probably write darray_search() like this:

/*
    @description:
        Searches for the first occurrence of an element matching
        item in the darray pointed to by p. If found, the index
        of the element is retured. If not found, (size_t)-1 is
        returned.
*/
extern size_t darray_find(darray *p, void *item)
{
    size_t i;

    /* Basic linear search */
    for (i = 0; i < p->capacity; ++i) {
        if (memcmp(darray_get(p, i), item, p->item_size) == 0)
            return i;
    }

    return (size_t)-1;
}

Basically the same thing, but differences in style and preference show through even for such a short function. :)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dnt remenber the error correctly bt it says some files r missing

Sucks for you. Try our Windows forum. Maybe someone there will be willing to help you install Visual Studio.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I tried to download the visual Studio 2010 Express version but its nt getting installed

Not getting installed how? Do you see any errors? When does it happen? Does the installation even start? Did you save the download somewhere where you can find it? Do you even use Windows? Is your computer turned on? Did you blow on the cartridge before hitting the power button?

Come on, dude, throw a bone to the people who are trying to help. I really don't want to say "sucks for you" and walk away, but if getting any useful information from you is going to be like pulling teeth, then that's my go-to response.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is it visual studio 6.0

No, it's Windows. To run a Windows program you need Windows. To write and build Win32 code, you can use Visual Studio. But I don't recommend Visual Studio 6 because it's relatively crappy compared to the newer versions. And you can also get newer versions for free (Visual Studio Express).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what software wil be required to run the win32 programs

Windows.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Theta notation is basically the same as Big O notation except instead of an upper bound, it represents a tight bound (ie. upper and lower). More formally (where Theta is the tight bound, O is the upper bound, and Omega is the lower bound):

f(x) = Theta(g(x)) iff f(x) = Omega(g(x)) and f(x) = O(g(x))

In all cases for complexity, constant terms are discarded, and often all but the most significant remaining terms will also be discarded. In your example, 4 and 3n are insignificant compared to n^2, so they're discarded to produce o(n^2).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Provided below is a bare bones dynamic array library. The game is to extend this library with new primitives and features that interest you, that you've needed in the past, or that you feel may be useful. The intention of this game is to give some of the newer folks a chance to get some design experience, but it's by no means limited to beginners; anyone can join in. And if we end up with a handy library as a result, all the better. :)

The starting library is very basic. It offers only construction/destruction, resize, and get/set. Suggested improvements might be insertion, removal, sorting, and searching. The sky is the limit! See what you can come up with, and post it for everyone to see (though sharing what you've done isn't necessary since this is for your own personal growth).

But first, an example using the base library:

#include <stdio.h>
#include "darray.h"

int main(void)
{
    darray a = {sizeof(int)};
    size_t i;
    int x;

    /* Populate the array from user input */
    printf("Enter a list of integers: ");
    fflush(stdout);

    while (scanf("%d", &x) == 1) {
        darray_resize(&a, a.capacity + 1);
        darray_set(&a, a.capacity - 1, &x);
    }

    /* Use the array */
    for (i = 0; i < a.capacity; ++i)
        printf("%4d", darray_getval(&a, i, int));

    putchar('\n');

    /* Clean up the array */
    darray_reset(&a);

    return 0;
}

It can define a multidimensional array too, but it's somewhat awkward (hint for extending the library):

#include <stdio.h>
#include "darray.h"

#define N 3

int …
myk45 commented: Excellent idea! +5
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It happens to me too. Keyboard commandos will see it more often. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That can happen when Chrome's zoom amount changes. See if ctrl+0 fixes it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how can i make a program that will input a number and convert it into a word using array , and also not using string.h library?

Technically you don't need either arrays or the string.h library to do this, though if you're accepting the word as a string it's easier. So my first question to you is are you taking the "number" as a string or an integer? This will determine how you proceed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you limited to a square matrix, or does the program need to support any MxN matrix size? The former is simple enough because the columns and rows match. The latter can be done with dynamic memory (the more general but harder option) or a "large enough" 2D array where the dimensions are something like 100x100 and you only use a subset of it as if the dimensions were smaller.

Judging from your description, the row size is dependent on the input, so when the user stops entering rows, that's how many rows you have. I'd wager that your teacher wants you to start simulating arrays with pointers and dynamic memory though. Here's a basic method for creating such a matrix:

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

int main(void)
{
    int **matrix = NULL, m = 0, n;
    int i, j;

    printf("Enter the number of columns: ");
    fflush(stdout);
    scanf("%d", &n);

    while (1) {
        printf("Enter a row: ");
        fflush(stdout);

        /* Allocate a new row */
        matrix = realloc(matrix, (m + 1) * sizeof *matrix);
        matrix[m] = malloc(n * sizeof *matrix[m]);

        for (i = 0; i < n; ++i) {
            if (scanf("%d", &matrix[m][i]) != 1)
                break;
        }

        if (i != n) {
            /* Didn't read a full row */
            free(matrix[m]);
            break;
        }

        ++m; /* Recognize the new row */
    }

    /* Test output to see if it worked */
    for (i = 0; i < m; ++i) {
        for (j = 0; j < n; ++j)
            printf("%4d", matrix[i][j]);

        putchar('\n');
    }

    /* Free the …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hm, i am a little bit confused..where should i put it?

I'm a little confused too. Is the code you posted something you actually wrote? Or did you pinch it off the web and now need help modifying it because it's beyond your ability?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes. I understand that this is the most impossible thing ever, but is it possible?

You think free web hosting is impossible? Have you done any research? Seriously, fire up google.com and you'll find no end of free options. They typically limit things like available space or include advertisements, but it's far from impossible.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why don't you try using FireFox. Its fast and sleek.

Patient: "Doctor, it hurts when I blink."
Doctor: "Don't blink."

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so when i say that range is fix like the INT_MAX, then can't i say that it is O(n) ?

How many languages would you like me to say "no" in before I make my point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think you misunderstood him -- he meant to say "in my opinion"

I understood perfectly. It was a joke, as evidenced by the smiley at the end.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When you see a capital T (as in LPTSTR) it means the code works with Unicode.

Rather, it means that the code accepts either narrow or wide characters. The Win32 API treats wide characters as UTF-16 encoded Unicode, so while it's technically correct to say that it means you're working with Unicode, I still think it's important to make the distinction between wide characters and Unicode characters as well as the variant nature of TCHAR which depends on a compilation setting. ;)

You can do what deceptikon suggested or just declared the string as

Oh, if only it were always that simple. Yes, if you take the question at face value then always using TCHAR is certainly the better option. But I treated it like an example of the issue rather than the actual code and included the possibility that the OP doesn't have any control over the type of temp, which isn't an unreasonable assumption in my view.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

According to me you should go for Linked Lists as suggested by Ancient Dragon. Its a good solution.

Wouldn't that be according to Ancient Dragon then? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's basically a combination of how the X shoots and how the Y moves. You add a case to the switch for your shoot key to create a projectile, and then follow a similar algorithm as the bomb to manage the projectile.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

dx9_programmer's answer is good, but I'd like to add just a couple of things. First, don't call strlen() in the condition of a loop because it's inherently inefficient. strlen() is a function that itself contains a loop, so when you say this:

for (int i = 0; i < strlen(word); i++) {
    ...
}

It's roughly equivalent to this:

for (int i = 0; ; i++) {
    int len = 0;

    for (int j = 0; word[j]; j++)
        ++len;

    if (i >= len)
        break;

    ...
}

If the length of word doesn't change in the body of the loop then it's silly to keep recalculating it. So calculate it before the loop, store it in a variable, then reference that variable whenever you need the length:

for (int i = 0, length = strlen(word); i < length; i++) {
    ...
}

Next is the actual cause of your segmentation fault. The problem is that c doesn't point to a location within word. Rather, c points to a location within alphabet. dx9_programmer explained the reason for the segmentation fault in a slightly confusing way, but I'd like to point out that it's also undefined behavior to take the difference of two pointers when they don't point to locations within the same array.

So while you might be getting a segmentation fault, that's not guaranteed to happen. Undefined behavior introduces 100% unpredictability to your program from the point it's invoked forward. So it's a good idea …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

will it do for the next link if i do this deceptikon????

No, because then there's only one next link, ever. The whole point of storing the next link in each node of a list is to have multiple links that can create a chain of nodes, each node linking to the next in the list. If you only have one global next link, that would result in a pretty short list.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thought of that as well but not all numbers necessarily have to be shifted by the same amount.

Okay, so you're looking for a pattern where the marker for a point in the pattern (ie. the FA language) isn't fixed. That's not a great deal harder if we're assuming that the overall pattern is constant and only the names/values of each node will vary, you can convert the variable language into a fixed language and then compare. So the original numbers would go away and be replaced with a normalized description:

{
    {A, B}
    {C, B}
    {A, D}
    {E, B}
    {E, E}
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can someone please explain step by step on how I would figure this out.

http://www.cs.duke.edu/~ola/ap/recurrence.html

"If" would be a simple n

It would be constant since the running time doesn't grow with N in any way.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you still do not understand the voting system then I fear we will have to break out the picture book version of the explanation :)

See Spot. See Spot vote. Vote Spot, vote! :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm just not sure how to see if they are equivalent based on the renumbering part....

If one number is shifted by a certain amount, all numbers will be shifted by the same amount. So when comparing the two arrays you can determine the shift amount by the very first number in both arrays and then apply it to all other numbers as you compare them:

// Compare x with a shift toward y
if (x[i] + shift != y[i])
    return false;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I just wondered what might be your training routines. Post and share them here.

This is my current routine:

Mon: Upper body (bench press, rows, pull ups, biceps curls, triceps extensions)
Tue: Lower body (leg press, leg curls, calf raises, back extensions, crunches)
Wed: Rest
Thu: Upper body (same as Monday)
Fri: Lower body (same as Tuesday)
Sat: Rest
Sun: Rest

All weights are no heavier than my 5 rep max and no lighter than my 12 rep max. I try to stay in the 5x10 set/rep range for working sets, but adjust according to how I feel that day. Due to nagging injuries I tend toward machines rather than free weights, which hasn't hampered my results in the slightest. But it's a shame because I love deadlifting.

Additionally, I eat like a monster

I follow IIFYM tailored to a lean bulk presently. No shakes or supplements beyond fiber and a multivitamin, just food.

Though a little high in cholesterol, shrimp are a great source of protein with low calories.

Dietary cholesterol only affects serum cholesterol in people who are sensitive to it, and that's pretty rare. The whole "cholesterol in your food gives you heart disease" has been debunked for a while now. In fact, there's been some long term observational evidence that low cholesterol diets tend to increase risk of CVD.

And I doubt anyone actively trying to gain muscle and consume protein will have any …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

sir, then m is also a constant.

No. Just because the range is tightly bound in one particular case (ie. your implementation) that doesn't mean you can suddenly say that the algorithm in general works with constant time. That's like saying quick sort is O(1) because you're only going to use it on an array of size 10.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I know it is just text. but registers are not text.

You asked about cx, bx, etc. Those are assembly language representations of the different registers. So yes, they are text. ;) It should also be fairly obvious that I'm just messing with you.

And yes, physical registers are real memory locations burned into the CPU.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

short is a smaller integer type than int (conceptually, at least). The 0xAB00 part is a hexadecimal literal value with the bit pattern 1010101100000000. It's just another way of writing the decimal value 43776 that makes the bit pattern a little easier to see, assuming you're familiar with hexadecimal. ;)

This would be roughly equivalent, and technically more correct because short is generally viewed as a 16-bit quantity where the signed positive limit is 32767:

int i = 43776;

Even more correct would be this:

long i = 43776;

The reason being that even int isn't required to be more than 16 bits, but long is required to be at least 32 bits.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hi deceptikon,thanks for ur reply,but i dont want ready made software

I'm not talking about ready made software. I'm talking about a font that you need to code your own freaking software. When you print anything textual you need to select a font, right? Well, a 1D barcode is textual data where the glyphs are encoded bars. So you need a barcode font to print barcode text.

Once you have a font it's dead easy to use the Printer object to do the actual printing:

' Set the printer...

' Print the barcode
Printer.FontName="your installed barcode font"
Printer.Print "*text to encode" & check_C & check_K & "*"
Printer.EndDoc

Assuming you have an installed barcode font and assuming the printer you select is the label printer, it's all scaffolding except calculating the C and K check characters.

I'm getting the impression that you lack the foundation in programming, VB6, and barcodes to even begin writing this program. You might want to do some reading, because if you don't understand even the most basic of things (like needing a barcode font), then you won't understand any help you receive in this thread.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can u suggest me how can i create barcode and print.

You need a barcode font, there's no getting around that unless you want to encode and draw the barcode manually, which I strongly recommend against. So your first step is finding a font, whether it be free or not. You can't get any further until that's done.

Might I suggest this?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is that TSTR can be either char or wchar_t, so there's not really much choice beyond allocating an array of TCHAR and copying one into the other with a function that recognizes TCHAR and handles it accordingly:

TCHAR *ttemp = new TCHAR[strlen(temp) + 1]
_tcscpy(ttemp, temp);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when there are no comments even then i cant delete it?

No. You can report it with the "Flag Bad Post" link and a reason stating why you want it deleted. Then a moderator will determine if the reason is...well, reasonable. But posts are typically only deleted based on serious rule violations such as illegal content, being complete spam, or copyright violation. We generally don't honor frivolous requests, but that doesn't mean you're not welcome to make them anyway on the off chance that it will be honored.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

then where is the gcd time included in this complexity ? is it a constant according to you ?

It's not a constant. And that's not according to me either, Euclid's GCD algorithm has been rigorously analyzed (you can find a fantastic treatise in Knuth vol. 2). The upper bound is O(n) where n represents the number of digits in the smaller of the two values being calculated.

So the time complexity of your loop over an array would be closer to O(nm) where n is the size of the array and m is the average length of the values in the array. You could dig down deeper to find a more appropriate representation for m, but the average should be sufficient to determine growth. A more exact measure would only be necessary for a proof, and not in practice, in my opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my doubt how does struct node *next serves as link to next node??? and why struct node *head does serve as pointer ???bcoz both are defined by structure

This question suggests that you don't understand pointers. If you have an instance of struct node, and its next member points to another instance of struct node, wouldn't you describe that as two instances linked together?

both are user defined data types tats wat my doubt is

Would it make any difference if they were integers? Because pointers work the same way regardless.