deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It would be helpful to know what input you're passing in so that we can duplicate your test case.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

moderator eyes have stopped completely working
so better observe before u talk that its a c program not c++

It looks like a bastardized combination of C and C++ to me. I can only imagine that it compiles due to compiler extensions and quirks, but that means your code isn't portable (and for no reason at all). For example, in Insert() you mix declarations and statements:

r=FindPrevious(X,P);
Position TmpCell;

This is illegal prior to C99, but you're not using C99 because implicit int was completely removed and you use implicit int in your call to main():

main()
{
    ...
}

C++ also disallows implicit int, but not all compilers enforce this rule. However, something that all C++ compilers do enforce is the implicit conversion from void*, which you use here:

TmpCell = malloc( sizeof( struct Node ) );

This will only compile as C. So my guess is that mixing declarations and statements is coming from a gcc extension because you're not compiling as strict C and didn't realize it. If that's the case I'd recommend changing your build switches to include "-ansi", "-pendantic", and "-Wall". It also couldn't hurt to learn the different versions of C and what's allowed in each.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is your Favourite Hack/Programming movie ?

Hackers. It's just so over the top that I end up laughing and enjoying myself rather than raging at the idiocy. Oh, and boobies. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, but it's not built in to the language or standard libraries.

Actually, it is as of C11. Though the trick with the latest standard is finding an implementation of it. Hopefully C11 will be more widely adopted than C99. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm in favor of option 2 simply because option 1 would take a significant amount of coding effort

Coding effort that's already been largely done? What you described in option 1 seems a lot like how comments work right now.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Oddly enough, I think I'm in favor of option 2. Though there would definitely need to be a way to hide excess numbers of comments. It's rare currently, but if the reputation system is used more often because of this feature, that kind of thing might become more common.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont know even wat is time complexity in c or o(log(n)).

You know, you could explore the site I keep referencing. There's an article on complexity there too.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What browser are you using at work? Are cookies enabled?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

an i know the time complexity of this program

The program you posted? It's a naive quicksort, so the worst case is O(n^2), the average case is O(n log(n)), and the best case is Θ(n log(n)). Optimizations to the pivot selection (or variations such as introsort) are intended to minimize any chance of the worst case.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Our permission/ranking system isn't strictly by post count. Specifically, the difference here is between a Newbie Poster and a Community Member. Once you've reached the threshold of either 15 reputation points or 5 posts plus 5 days since joining, your rank will automatically go from Newbie Member to Community Member. At that point you'll have all permissions allowed for Community Members, including the ability to send private messages.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

wth, why would someone want to do that

Intimidated by my sheer awesomeness, I suppose. :D

zeroliken commented: probably, likely ;) +9
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think the most common options for choosing a pivot are random and median of three. Ideally you want the pivot to be a perfect median of the current subset being sorted, because that produces an optimal recursive tree.

Give this a read. It's not perfect, but there's more detail in normal people words than the majority of articles I've read.

lol looks like someone's gaining fame ;)

Don't forget infamy too. I think someone started a petition to have me banned earlier today. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i wonder how did u become administrator without having any basic knowlege of c language ?

The two are unrelated. But if you want to discuss aspects the C language or standard library, I'll be happy to school you in a debate.

now just get lost from daniweb and stop banning users form daniweb

I only ban people who violate Daniweb's rules often enough to deserve it, and I can justify each and every one of them. I'm curious what your problem is, or who you really are since it's unusual for there to be such animosity given only 3 posts in this thread. Are you one of the rule breakers I've banned?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When developing in low-level languages, particularly assembly languages

You'll notice that this is the C forum, not the assembly forum.

when a low number of registers or limited memory is available

As I mentioned already, that can be a viable argument in favor of the tricks. But that's a niche area, and those platforms are the ones that don't support stdio.h (which you used in your OP). Further, when it is a viable argument, the caveats are made very clear to discourage use outside of the niche area, and you didn't do that. Rather, you tried to palm this off as a generally applicable and appropriate solution, which it isn't.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's in the Visual C++ -> General project templates.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Maybe you need to make that feature more obvious.

I'm open to suggestions. It's currently no more obscure than the post number representing the same link under vBulletin. Though I'll certainly look into adding actual post numbers, as that's a useful feature as well.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have no choice, that's a question given in my assignment that's due tmrw.

Oh my god, I know! Seriously, I read the question and understand that it specifies assert(). For future reference, it's bad practice. Keep that in mind, but answer the question appropriately, since it requires you to use the assert() macro. I fail to see how this is difficult to understand.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Clearly you didn't read my post (probably because I didn't give you a full working program), because I explained exactly how to do it in two different ways.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you want to write standard C++, I'd strongly recommend only using an empty project. Then you don't have to deal with Microsoft's precompiled headers (stdafx.h) or any of their character width agnostic types.

The _T stuff is supposed to use the correct width character type depending on whether a macro switch for Unicode is defined or not, where it's just char when undefined and wchar_t when defined. It's not a bad idea, but you lock yourself into the Microsoft CRT libraries by using it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thought that was a requirement imposed by the assignment.

Yes, that's correct. But since this forum is about learning and not simply regurgitating answers, I wanted to explain that the question is encouraging bad practices and why the practice is bad.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since we don't have post numbers anymore I can't just give you a link to it but the op was given a large char array and asked to write his own malloc() and free() functions.

Ah, I see now. It's this post. The time posted for each post is actually a link to the post's permanent URL. You can copy that and link to it instead of referring to post numbers.

Huh? What quoted statement?

Your statement that I quoted in my post with the forum's quote feature. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Verifies that a legitimate 24hour notation has been input by using the assert statement

Just so you understand, this is an extremely poor practice. The assert() macro should only be used for shaking out bugs because it invokes a hard stop on the process. Here you're using it for validation of user input, which is almost guaranteed to be incorrect at least half the time for free form input.

Put a different way, do you really want to crash the program when the user fat fingers a number?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Nobody is going to do your homework for you. But I'll give you a push in the right direction. You essentually have two options:

  1. Build a new list in sorted order while traversing the old list.
  2. Sort the old list into a new list.

It's a fairly subtle difference between the two, but the former assumes there's a sorted insertion function for the list while the latter assumes you'd modify something like the list insertion sort function here to build a new completely new list instead of splice nodes (a simple and minor change).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The restriction is you can't use malloc() or anything like it, such as HeapAlloc() and AFAIK that is MS-Windows-specific function.

I didn't see any such restriction mentioned in the thread, barring the implied restriction from K&R (though it still uses POSIX sbrk()). My implementation is inherently tied to Windows, and targets the CL compiler specifically for a number of reasons. Could you elaborate on what you meant by the quoted statement?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can use a single call to scanf()

It's not about the calls to scanf(), the requirement for one to press enter is at a lower level than your program. You could have multiple calls to scanf() in a loop and still put everything on one line. Conversely, you could have a single call looking for multiple items and still press enter between each item. This is because scanf() will block until a matching failure or until it reads everything requested; there's nothing magic about a newline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My understanding of the C language is that the same identifier cannot be reused.

That's correct, but only within the same name space (not the same as a C++ namespace). There are five listed name spaces in C:

  1. Label names (such as cases and goto labels).
  2. Structure, union, or enum tags.
  3. Structure or union members.
  4. Typedef names;
  5. Everything else.

With those name spaces in mind, it's easy to understand why the following is legal:

typedef struct foo { int foo; } foo;

In your code, the typedef error and the macro error are in different name spaces (the typedef falls under #4 and the macro under #5), so there's no direct conflict.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Type everything on one line, then press enter. scanf() is natrually designed to handle this kind of input unless you go out of your way to ensure that each number is on a separate line.

But even then, after you hit enter the cursor will move to the next line. This isn't something you can portably control from C because it's an effect of the command line. It's possible, but you'll need to jump into non-portable libraries. Since this is encroaching on territory best suited to GUIs, you might consider dropping the command line entirely and writing a graphical interface.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm shocked nobody has pulled out the XOR trick yet. That's usually the first one that pops up when people try to show off the trivia they've learned that has no practical benefit in the real world.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Whether it's simple or not depends on how well you know C, but I think the following is trivial:

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

int main(void)
{
    struct tm d1 = {0}, d2 = {0};

    d1.tm_year = 2012 - 1900;
    d1.tm_mon = 7;
    d1.tm_mday = 18;

    d2.tm_year = 2011 - 1900;
    d2.tm_mon = 7;
    d2.tm_mday = 18;

    printf("%f\n", difftime(mktime(&d1), mktime(&d2)) / 86400);

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

If you don't post what you found in the help files, I have no choice but to let someone who knows what you're talking about devine what exactly you're having trouble with and explain it to you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but when it comes to memory storage or allocation its better to go in this way

Memory footprint is a viable argument, but I'd suggest that if the memory for a variable of type int is too much, you have bigger problems. I'm not sure what you mean by allocation though, as local variables are "allocated" with a simple adjustment of the stack pointer.

time efficience compare to using the third or temp variable

Using a temporary variable is all but guaranteed to be more efficient. This is a case of premature pessimization, where the "clever" optimization trick actually makes the code perform worse than the naive code would by confusing the compiler's optimization routines.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The pioneering spirit appears to be dead, at least among the latest generation of programmers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

how to use center_text? can you give a sample code? thanks!

I don't know what that is. Is it some function that Turbo Shit supports?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually, this is very easily done...that is if you did some basic C-language based I guess- programming including pointers. In C, since you can use pointer arithmatic on a pointer that you have malloced initially. So, if you are to say make a pooled memory-or given a memory space in which you are allowed to access- do arithmatic pointer and divide up the memory. Use strucs and/or headers to make things simpler. If you are given an "initialized" memory space as a form of an array, than it is easier. Array indexes also satisfies the arithmatic, so you can put -1 or other magic number in an array to indicate its empty, and work your way out from there on.

It's easier than that if the system allocation options are similar enough to malloc() to facilitate a thin wrapper. For example, I wrote an implementation of the standard library that defines malloc as such:

/*
    @description:
        Allocates space for an object whose size is specified by size.
*/
void *malloc(size_t size)
{
    uintptr_t mem = (uintptr_t)_sys_heapalloc(__sys_heap, size + sizeof(size_t));

    *(size_t*)mem = 0; /* General alignment */
    mem += sizeof(size_t);

    return (void*)mem;
}

Where _sys_heapalloc() is nothing more than a portability wrapper around the Win32 API's HeapAlloc():

/*
    @description:
        Allocate the specified number of bytes from the specified heap.
*/
void *_sys_heapalloc(_sys_handle_t heap, unsigned bytes)
{
    return HeapAlloc(heap, 0, bytes);
}

Barring initialization and teardown of the __sys_heap object in the C runtime code, that's …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

zeroliken you are wrong
Its not the right answer

Then what do you think is the right answer? The sequence you showed is clearly 5^n at every step. If the 5th step isn't 3125 (5^5) then either you didn't provide sufficient information about the sequence to reach the next number, or you don't realize that the answer is 3125. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A list is there in which infinite numbers(approx 1 lakh)

1 lakh is hardly infinite. Hell, I wouldn't be against bubble sorting an array of 100,000 items on modern hardware, and bubble sort is the canonical "slow" algorithm.

I know this question will be solved by using heap(min or max).

That seems awkward to me. Unless there are any specific rules to this problem that require a clever approach, I'd probably go with sorted insertion into a collection that has efficient search properties, then just search for the kth element on request. This could be as simple as a dynamic array, though there may be issues with a sorted insertion since it involves lots of data movement.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

don't say do it by your self i could'nt understand thats why i am asking from you if i know then why i ask i don't know thats why i am asking friends plz help me...!!

Please don't just post your assignment and say you don't understand, that's not helpful. What don't you understand? Which parts are confusing? It can't possibly be every single word in the assignment, so put some effort into asking for help.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strrev() isn't a standard function, so compilers aren't obligated to support it. What compiler are you using?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How about "A Proposal to leave the dark ages and start doing the same shit everyone else with any sense has had in place for two decades"? ;D

But seriously, something that highlights the benefits of the system would be a good idea. Like "Streamlining the book borrowing process", or "An automated approach to library inventory management". If the proposal is aimed at decision makers then big computery sounding words are good, but don't forget to make sure that cost savings are a huge bullet point, or even a subtitle.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm again assuming that your output is to the command prompt. And the answer is yes, but not as easily as setting a center attribute. When it comes to "formatting" in the command prompt you need to fill the line with leading spaces to put it where you want. For example:

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

void PrintCenteredLine(const char *s)
{
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO screen_buf;

    if (GetConsoleScreenBufferInfo(console, &screen_buf)) {
        int width = screen_buf.dwSize.X;
        int fill = (width / 2) - (strlen(s) / 2);
        int i;

        for (i = 0; i < fill; ++i)
            putchar(' ');

        puts(s);
    }
}

int main()
{
    PrintCenteredLine("Giggidy giggidy goo");
    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Haha, the new format reads like a Casey Kasem letter. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when i am storing address of local variable in a , then after that object destroys, then a will still have its adress na ?

a is a local variable too, it's destroyed at the same time as b. So the answer is no, because a no longer exists.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but , it is not playing with value of i, rather it is playing with value of a.

Correct.

then why u saying that ?

Because changing where a points to has absolutely no effect on i. If you had dereferenced a and copied the value of b into it then you would have indirectly initialized i:

int f(int *a)
{
    int b = 5;
    *a = b;
}

But the f() you posted is completely nonsensical as it only works with the local pointer, does nothing else, and immediately loses all of those changes when the local objects are destroyed upon return.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

f(&i) has no effect on i.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

isn't it two null characters ?

No, because strcpy() stops at a null character.

what is o/p for this ?

It's undefined in a big way. Both printf() statements are trying to print an uninitialized variable. f() doesn't do jack diddly to i, as a is a copy of the address of i. You're only modifying the copy, and the original remains unchanged.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It will be "nitin". s can't be a null pointer because it's an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i am submitting there. the site is giving me time limit exceeded.

Okay, that's completely different. Obviously if you're writing to cout over 10,000 times then it's going to take a while. That's the problem, and the root cause is that your code is too slow due to the overhead of output.

my code complexity is O(1).

No, your code complexity is O(t).

so i tried it on ideone which gives me run time error.

It's not unreasonable to assume that Ideone has stringent limits on things like this, so I'm not surprised at all that you got a SIGXFSZ error. Use a real compiler on your local machine and that error will vanish.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's generally advisable to use fgets() to retrieve a line, then parse the line in memory, possibly with sscanf(). But the needs of your program override general advice, and it looks a lot like you need to tokenize a function call for a compiler.

What does the file represent, and what are you doing with the data?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you redirecting output to a file? SIGXFSZ is the signal raised when a file exceeds its size limitation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

so what should i do to fix the problem.

You should post your code so that we don't need a crystal ball to figure out where the problem is and what's causing it. Would you ask a mechanic to fix your car without actually bringing the car?

pls i need to fix it if you can send me the code

You want us to send you the code to fix the problem with your code that you didn't post? What's wrong with this picture?