deceptikon 1,790 Code Sniper Team Colleague Featured Poster

arrayofstr = malloc(9 * sizeof (char*)) is misplaced. Move it outside of your first loop.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Quicksort is implemented in C with the qsort() function.

The interesting thing is the C standard doesn't in any way require that qsort be implemented as quicksort, nor does it impose any performance requirements in the same way that C++'s sort function does. The C++ standard retains this lack of guarantees for the C library functions.

You can expect it to be efficient, of course, given that implementors are not stupid. As an example, I chose heapsort as the qsort implementation for simplicity of implementation and guaranteed time complexity across the board. From stdlib.c:

/*
    @description:
        Sorts an array of n objects, the initial element of which is
        pointed to by base. The size of each element is specified by size.
*/
void qsort(void *base, size_t n, size_t size, _cmp_func_t cmp)
{
    _sort(base, n, size, cmp);
}

And from _sort.c:

#include "_sort.h"
#include "_system.h"
#include "stdint.h"
#include "stdlib.h"
#include "string.h"

static void do_heap(void *temp, uint8_t *base, size_t i, size_t n, size_t size, _cmp_func_t cmp);

/*
    @description:
        qsort-friendly implementation of heapsort for guaranteed time complexity.
*/
void _sort(void *base, size_t n, size_t size, _cmp_func_t cmp)
{
    void *temp = _sys_alloc(size); // The size of items is unknown, so we must allocate
    uint8_t *p = (uint8_t*)base;   // Pun the base into a byte array
    size_t i = n / 2;

    // Heapify the array
    while (i-- > 0)
    {
        do_heap(temp, p, i, n, size, cmp);
    }

    // Extract the heap max and place it in sorted position …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wheres as,

IN C ...

one ALWAYS needs to return an int value in main, and to code that in explicitly, if the compiler conforms to any standard from C89/C90 forward ...

The clause for omitting a return from main was added in C99 and retained in C11.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

We're clearly the devil's spawn, being all objective and fair. ;)

I'd wager this complaint has something to do with not being able to differentiate between enforcing the rules as a moderator and participating in discussions as a member.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this issued happening because I have "fileName" still open as "objReader"?

Yes.

If this is the case, is there a way to close it while still in my loop?

Well, you could dispose of the reader and break out of the loop, but that's very ugly and prone to error. And I suspect the reason you're asking is you want to continue reading from the reader after moving the file. I'd be more inclined to tweak the logic so that this exclusive access problem simply doesn't exist.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

word= (char )malloc(sizeof(char)100);

word is a completely separate and independent entity from words[i]. Essentially what you're doing here is creating a new pointer, allocating memory to it, then throwing it away (along with losing your only reference to the allocated memory).

words[i] = (char )malloc(sizeof(char) 100);

Here you're still creating a new pointer, but not trying to overwrite it. Instead, you're dereferencing it to get to the original location and overwriting that. This works because the temporary pointer isn't your only reference to the allocated memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I would go so far as to say never use rand()

Unless you wrote it, of course. ;) I'm at the point with my C standard library that I use it instead of the built-in standard library for most personal work. rand is implemented as the Mersenne Twister, so I know it's solid at least in terms of the underlying algorithm.

In C++, I agree that there's really no excuse to ignore the <random> library if your compiler conforms sufficiently to C++11.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So yes, you can determine what the original source code looks like if there is no obfuscation/cryption.

For .NET to a certain extent. It won't match the original source since higher level constructs are represented internally with lower level constructs, but you can get close enough to have a fairly good view of the implementation.

For C++, it's compiled into machine code and the original is lost completely. So any decompilation will be nothing more than an educated guess at the original code as it builds new source from the machine code.

For .NET, I quite enjoy decompiling assemblies to see how they work. For C++, I don't bother with decompilers and instead use disassemblers and work through the assembly listing. I have yet to see a C++ decompiler that's worth a damn.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

total += float read_input( a,b , c ,d,e );

The syntax is wrong for this line. First, the float keyword is unnecessary (perhaps you meant it to be a cast?). Second, read_input does not accept any parameters, so the arguments are also not needed. Try this instead:

total += (int)read_input();

Finally, read_input is defined to return a value, but doesn't actually return a value.

On a side note, consistent formatting would make your code easier to read.

Abdul_32 commented: thank you soo much you've solved my mess ^_^ +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

then the type of the expression is

The longest, floatiest type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Screenies of old Daniweb isn't half as interesting as the code for old Daniweb. Eew. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

At the very bottom of every page are lists of links, which include the article workshop that's filtered based on your user permissions.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can't (easily) delete the file while it's locked for reading, so I'd alter the logic so that you break out of the reading loop, destroy the reader object, then delete the file safely.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Linked lists are elegant, but inefficient to keep sorted.

Not if you use a hybrid tree/list, hash/list or a skiplist. :D But those implementations aren't as blindingly simple as a regular linked list, so you don't see them often.

Data structures are an exercise in trade-offs. You can have simple or efficient, but rarely both unless the application is very niche.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

PLEASE HELP AS SOON AS POSSIBLE.

Please read our rules as soon as possible. Thanks.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when one left side and one right side child complete then system credit 700 to parent id

I don't understand your question. Do you mean when a node has two children, 700 is added to a value in the node?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So whenever possible and performance is not an issue you would advise this sort of programming practice?

I wouldn't say whenever possible. Clarity trumps, so if duplicating code makes it easier to understand, that would be my recommendation. And if eliminating duplication is excessively confusing for one reason or another, I'd refrain. But in my experience those situations are somewhat rare if the code is otherwise well designed.

ddanbe commented: OK +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have a feeling that WojTroll will go quiet now...

Or create another account in the hope that we won't be able to tell (which we most certainly will).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ooh, forum drama.

grabs popcorn

cereal commented: lol +0
RikTelner commented: *passes coke* +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think that bothers you looking at my program.

Not really, it's a minor thing. The other problem is very significant.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I see two problems immediately:

char* names;

This represents an uninitialized pointer, not a pointer to infinite available character slots as you're using it. I'd strongly recommend using the std::string class instead. Otherwise you'll need to dynamically allocate memory to that pointer manually for each instance of the structure.

for(int e=20;e<0;e++){

e will never be less than 0, so this loop doesn't execute...ever.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

the console I/O library is not a standard part of C, and is associated with older (that is, pre-C99) Borland compilers.

Some common modern compilers support it. I don't see any clear indication that this is a pre-C99 compiler, though use of fflush(stdin) narrows things down a bit as well.

That said, if the compiler supports a C99 feature and doesn't use any non-C99 features, what's the problem? I can only see an issue if the code is intended to be C90 compatible.

Of larger concern is fflush(stdin), which is technically undefined behavior across the board, and use of gets, which is abhorrent regardless of compiler and non-standard as of C11.

rubberman commented: Yes, fflush() is meant for output streams. Stdin is an input stream. +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Howdy all. I've recently been considering doing an online meeting or webcast on certain subjects for which I have a lot of experience or knowledge. The idea being that something too long or complex for a Daniweb article can be more easily shown by sharing my desktop and talking about it, followed by Q&A.

However, something like this would certainly require at a minimal amount of people who are interested in joining before I put any effort into scheduling and preparing presentations. I'm thinking at least 10.

So I ask you: would you like to see a webcast of some form?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, of course. But for homework questions we require some substantial proof of effort on your part.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You won't find it here, Daniweb is not a homework service. We'll be happy to help you with specific problems in your code, but we won't do your work for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Its like censorship.

Except not at all. Notice how none of your posts have been deleted or modified? Notice how you're still welcome to continue posting? Rest assured, I've been part of forums that do practice censorship, and Daniweb is about as far from that as I can imagine without letting spammers run rampant.

But I still cannot see who downvoted my posts/articles.

Yes, and you won't for the forseeable future. Once again, this is intentional.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My main focus of this question is the use of objects within Interfaces, is this common practice, or even acceptable?

Your interfaces contain properties rather than objects, which is just fine and quite common.

My issue with the code is twofold:

  1. It's overly complicated for what seems to be no benefit.

  2. The interfaces appear to be there for no reason other than to use interfaces.

So you want a car class, right? Very cool. What would I do differently? Just about everything. ;) Let's go top down.

interface ITyrePressure
{
    int FrontWheel { get; set; }
    int RearWheel { get; set; }
}

An object representing pressure makes marginal sense, but the logic is inverted here. A tire has pressure, but the pressure shouldn't give two hoots about about the tire. If you're going to dig this deeply into the class structure, I'd do it more like this:

class TyrePressure
{
    private int Lo { get; set; }
    private int Hi { get; set; }
    private int Current { get; set; }

    ...
}

class Tyre
{
    private TyrePressure Pressure { get; set; }

    ...
}

The idea being some programmatic way of telling the driver that the tire pressure is too low or too high for a single tire as that's really the only thing that makes sense to me if you're going down to tire pressure granularity.

The wheel class is pointless, but yours also exhibits an inversion of data in …

ddanbe commented: Glaring mistake or not, great answer! +15
J.C. SolvoTerra commented: Great advice +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As far as I know covariance and contravariance exist in C# at least as of version 4.0.

This is true, but not for return types from methods.

ddanbe commented: Thanks for the hint! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

insead of talking, Dani should sit and rewrite it

That's not how professional software development works. First the requested feature is discussed for viability:

  • Is this feature necessary?
  • Is there an acceptable workaround?
  • Does the feature fit within the intended design?

If it's determined that the feature is viable, then a followup discussion is had about its practicality:

  • Do a critical mass of users want the feature?
  • Is the benefit of the feature worth the cost of implementing and maintaining it?

If the feature is deemed practical, a proof of concept is created to work out the kinks. Finally, if there are no significant problems from the proof of concept, the feature is implemented into the product and goes through the release cycle.

Let's talk about quoting, since that seems to be your biggest beef. Thus far I've seen only one feature request, and that feature is to support cross-page quoting. I started the discussion on viability with you and it didn't seem to go anywhere. Other problems with quoting were too vague to even begin any kind of discussion.

You seem to be expecting magic. We need lots of information in a feature request to answer the above questions, and I have yet to see that information reported in any meaningful way.

when you want to be respected, just respect others

Indeed. Odd how you haven't been following that advice. In fact, you stated quite clearly that you will not respect the developers …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Tried different things myself, but as I'm a still a learner and could find nothing useful on the web, I'm a bit stuck.

It may help your search to know that what you're looking for is called return type covariance. To simplify your search drastically, C# doesn't support it even in the latest version. ;)

There's likely a workaround though, if you specify exactly what you're trying to accomplish rather than simply paraphrasing it for the sake of simplicity.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Because Microsoft hasn't ever bent over backward to support ancient software/drivers, or shoddy coding practices for the sole purpose of avoiding breakage as Windows and hardware evolves. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Um...what?

Moschops commented: I can't disagree with this assessment. +13
rubberman commented: Did you mean baby sitters? :-) +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Forum technology is outdated.

And what's the 'modern' technology? Heavily policed Q&A that discourages meaningful discussion? 140 character brain farts that are devoid of intelligence? Useless videos flooded with trolling commenters? ;)

StackOverflow is a forum, though it's presented in a different way than most other forums and imposes draconian policies to enforce 'quality'. But that enforcement also squelches any hope of SO being more than a clique of power hungry douchebags offering little to no pedagogical value for beginners.

New is not always better, and if Daniweb ever throws away the founding principles to be popular with Google, that's the day I'll leave.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It works okay for me in Visual Studio after fixing two bugs. First you never initialize listA in main, so the top and bottom pointers are unintialized. A quick fix is this:

listA = malloc(sizeof(list));
listA->top = listA->bottom = NULL;

Second, and a more subtle problem is in buildNode. The logic is fine, but the amount of memory allocated is incorrect. sizeof(node) gives you the size of a pointer, not the size of the _node structure which is what you need. The change is trivial, but not obvious:

node = malloc(sizeof *node);

Now, while you could say sizeof(struct _node), it's generally better not to depend on a type name on the off chance you end up changing it by renaming the type or using another type. The trick above depends on the fact that sizeof does not evaluate the expression itself, only the resulting size. Otherwise, dereferencing an uninitialized pointer would invoke undefined behavior. However, in this case it's both perfectly safe and conventional.

This bug is a side effect of hiding a pointer in a typedef, which is generally not recommended precisely for reasons like this.

Note that I didn't crash in the same place as you did. There's really nothing wrong with printList, so getting an error there is a false positive and one needs to dig deeper in a debugger to find the real problems.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i dont wanna use Third Party Image viewer control

Then your two options have become one option. You'll need to use a third party library to convert the image to a format PictureBox likes. I say a third party library because .NET's built in imaging libraries may likely still cause you problems due to lack of support for the source image type.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your dequeue logic has two major problems:

  1. It does not take into account updating the bottom node.

  2. Wherever the node is deleted, the list is terminated with NULL rather than maintaining the structure if there are subsequent nodes.

This is a basic single linked list deletion, so you might be well served by boning up on linked lists in general.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You've encountered one of the most irritating things about .NET (at least for me): image processing is quite wanting. I don't work with TGA much, but I work extensively with TIFF. The .NET imaging libraries either do not support TIFF readily, such as PictureBox, or the support for conversion of certain types to BMP such that PictureBox would accept it is lacking. A good example is JPEG compressed TIFF. Neither the old style .NET imaging classes nor the much superior WPF imaging classes (which can be used in WinForms) support that compression method.

Long story short, you have two options:

  1. Use a more robust imaging library such as Magick.NET to convert your TIFF and TGA images to BMP so that you can use a PictureBox directly.

  2. Find a third party image viewer control that will support the image types you need.

Either way you'll find yourself using a third party library for the heavy lifting.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does it exactly mean to "escape" a string and where does the code for this go?

Escaping a string means converting characters that would be treated as special in a query as literal characters. A good example is a single quote. This has special meaning in a query, and attackers can use it to alter the functionality of the query to bypass security. Escaping that character makes it non-functional as part of the query such that it only contributes to a string value. Details on that can be found by studying SQL injection attacks.

As for where it goes, anytime you build a query with uncontrolled values, those values should be escaped.

After I have this set up in my code, how do I properly test that it is indeed working (Without completly wiping out my tables, etc?)

My preference is a combination of extracting the final query for manual testing, and extensive use of a test database so that the integrity of your production database isn't affected during development.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You seem not to get the point Dani

The point is not lost. I understand exactly what you want, and I'm sure Dani does as well.

why not make who voted visible (but only to post author)?

Let's attack this from another direction. Why do you need to know this information? What would you use it for?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

no dev window is closed. Why?

It's called troubleshooting. I'm asking potentially relevant questions to pinpoint why your browser isn't exhibiting normal behavior. Last night I tested the top 5 browsers (Chrome, FireFox, IE, Opera, and Safari) and they all function as expected.

Anyway, since Ctrl+Tab and Ctrl+Shift+Tab are both built-in shortcuts in all major tabbed browsers, we cannot use those combinations to do something different on a page. It would be like trying to override Ctrl+Alt+Delete in a Windows desktop application. Possible, but generally a bad idea.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I disagree with the part abut quoting.

Then we'll have to agree to disagree for now.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why you dont want to introduuce new features suggested by me (and not only me)??

You're sending mixed signals. First you want the bugs fixed before adding new features, then you want new features. In both cases, your suggestions have been too vague to act on. In fact, I haven't read any recent feedback posts of yours that do much more than rant on things you personally don't like.

So please, give us details:

  1. What do you think is a bug?
  2. Why do you think it's a bug?
  3. What specific behavior would you rather see?

For features:

  1. What behavior do you feel is missing?
  2. Please describe the behavior you'd like to see in detail.

If something fundamental is missing, there may be a good reason for that. Assuming that we don't care about members or don't do anything about feedback is unfair.

Things like "Daniweb doesn't do what I want", or "Daniweb isn't like other forums" lack any kind of actionable information. Further, by mixing suggestions with vitriol it's more difficult for us to extract any actionable information or treat legitimate suggestions seriously because it reeks of trolling.

I can assure you that Daniweb's feature set is certainly in flux relative to member feedback, provided that feedback is specific enough to be usable.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So are you one of the 11 million and will you still be on July 15th?

In my experience working with a number of companies as customers, Server 2003 has almost entirely been replaced with Server 2008 R2. I can only think of two customers that still have an active 2003 server, and both of them are either in the process of decomissioning it or have a roadmap for doing so within the quarter.

XP as a desktop system is run across the board of use cases, so you need to take into account everyone from business users to granny's sewing room machine, which makes end of life more of an issue. For the server operating systems, typically only knowledgeable folks run it, it's in a relatively high profile position on the network, and will have a reasonable maintenance/upgrade schedule.

So my personal opinion is that this end of life isn't as big of a deal as XP's end of life because lack of publication doesn't correspond to lack of awareness.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The problem is that a naive atoi like conversion won't work directly with hexadecimal characters because you need to take into account that a-f represent 10-15. That too requires a minor conversion as well to get the values you need. Once you have those values, this formula works to build a 2 digit hexadecimal value:

16 * first_digit_value + second_digit_value

I like to implement that minor conversion with a string search in the set of available digits. For example:

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

int hex_digit(char c)
{
    return string("0123456789abcdef").find(tolower(c));
}

int main()
{
    char buffer[4] = {'3', '1', '4', 'C'};

    for (int i = 0; i < sizeof buffer; i += 2)
    {
        int digit = 16 * hex_digit(buffer[i]) + hex_digit(buffer[i + 1]);

        cout << (char)digit << '\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A continuation would help in identifying a pattern. Presumably, it might look something like this:

1
1 2
2 3
2 3 4
3 4 5
3 4 5 6
4 5 6 7
4 5 6 7 8
4 5 6 7
3 4 5 6
3 4 5
2 3 4
2 3
1 2
1

But confirmation of that would be helpful. Otherwise this looks like a fun problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's by design. The editor isn't a mere text field, it's an actual text editor supporting Markdown where indentation is significant. If tab moved to the next page element, creating code blocks manually would be tedious at best.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Hmm. Of the top of my head, I'd say it really depends on what features you plan to support. If there's a huge amount of intersection between the two, I might choose to implement the vector as a composition/specialization of a matrix of 1xN or Nx1. Alternatively, a matrix may be a construction of vectors if that turns out to be more efficient.

I might not even split the two at all and let the caller use the matrix as a vector if there aren't any vector-specific operations (or manually construct a matrix out of vectors, but that seems less useful mathematically).

It's personal preference, of course, but I tend not to rely on inheritance unless necessary. Composition or careful generalization tends to cover most of my needs.

ddanbe commented: Great help. +15
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are a few problems, and most of them stem from misunderstanding pointers.

On line 12 you have this:

while(i <= cnt)

That's an off by one error. Arrays are 0-based in C, which means if the user enters 3, you're processing the indexes 0, 1, 2, and 3 rather than just 0, 1, and 2. It should simply be while (i < cnt).

if (arr[i++] == 0) *zeros++;

This is the first pointer related problem. *zeros++ will dereference zeros, then increment the pointer, not the pointed to value which is what you really want. Precedence and order of operations can be a little confusing when pointers are involved, but you can do either (*zeros)++ or switch to prefix increment with ++*zeros to get the correct behavior. Also note that you never initialized *zeros to 0, so its value is garbage.

The zero check also contains an off by one error in that you neglect to check the first value in arr by both incrementing arr during input, which is prior to the zero check.

I'd also question what the point of making zeros a pointer here as you could just use a straight up int and return that rather than mucking about with malloc and a pointer.

Finally, the global cnt smells bad. You should avoid global dependencies whenever possible, which in this case it most certainly possible by passing the size of the array as a parameter:

int readInts(int *arr, int cnt)
{ …
ddanbe commented: Nice work done here! +15
Slavi commented: kudos +6
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What do you need help with? What have you done? This is clearly homework, so we need some proof of effort before helping (as per Daniweb rules).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

sorry, but both of those languages are FAR from secure.
(I can decompile both of them with 1 finger)

I think it would be good to define what you mean by 'secure'. If you mean disallowing third parties to reverse engineer or otherwise steal code, then you're correct that by default those languages are not secure. Though there are ways to obfuscate assemblies to make such actions more difficult. However, it's not impossible to reverse engineer any software, regardless of what language it was written in. The only difference is the effort required to do so.

If by 'secure' we're talking about the more conventional cracks and exploits then I'd point out 'security by obscurity' is the pinnacle of naiveté. That kind of 'secure' is deeper in that holes are avoided through robust code, use of secure libraries, and in the case of .NET or Java, a safe runtime environment. The language itself has little to do with being 'secure' unless its definition encourages unsafe practices. But that's a much more in-depth discussion than just saying "XYZ language is FAR from secure" because there are many variables involved.

Simply being able to easily decompile an assembly does not make the assembly insecure in terms of creating an exploit, because transparent code doesn't inherently contain exploitable holes. If that were the case, open source would be stupid.