deceptikon 1,790 Code Sniper Team Colleague Featured Poster

is there sometimes excuse for dublicating code?

Yes. There's an excuse for breaking any best practice guideline.

So how can you explain - how would I solve my situation which I decscribed

I'm not sure I see the wisdom of fixing a pervasive bug in only one place. Now you have two different versions of the same solution and one of them is buggy! That's called code rot, and it should be avoided, for good reason.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I take it you're going to air your dirty laundry every few months just to remind us that you're unhappy with the new system?

Every forum uses your regular [code][/code] but no, not Daniweb.

Not every forum, just forums based around or inspired by vBulletin. Hop on over to StackOverflow and see how well BBCode works. I'll wait...

You have to tab your code. Imagine if Im on a old DOS box and tab isnt supported in the OS (this is a extreme example but just to show) AFAIK, you cant tab on Android/iOS either.

You can use spaces too, or the Code button on the editor. Or you could not use an old DOS box because extreme examples are often stupid. And let's be honest here, if you're posting from a phone or a tablet, you shouldn't really expect the same experience as you would from a computer. We may even provide a mobile version of Daniweb in the future.

Having used forums from a tablet before, I recognize that there are usability issues. But it's not unique to Daniweb. I think the problem is that you've become used to vBulletin based forums and simply don't like being forced to learn new workarounds.

Then there is the "jumping cursor" bug

That's such an informative bug report. Could you be more specific? Maybe provide a set of reproduction steps? As far as I'm aware, there aren't any outstanding bugs in the editor, so that …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

yes daniweb is not user friendly and it should allow its users to delete their thread

Yeah, allowing members to arbitrarily destroy the continuity of the forum and alter other members' posts on a whim is such a fantastic idea... :rolleyes: You sound very selfish, dude.

By the way, I'll be happy to delete any thread if there's a good reason for it. I've requested a good reason multiple times and you've completely failed to provide one. So I don't think the problem here is Daniweb's policies.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I dont even know where to start since I am struggeling with the whole pseudocode process.

Pseudocode is nothing more than a structured way to organize your algorithm's steps. For example, the following is a valid (but largely useless as it stands) pseudocode program:

Open the east file
Sort the east file
Open the midwest file
Sort the midwest file
Open the west file
Sort the west file
Merge east, midwest, and west
Save the merged results to a new file

The benefit to this is you can iteratively add more detail and specific steps. For example:

Open the east file
Sort the east file
Open the midwest file
Sort the midwest file
Open the west file
Sort the west file

# Merge and save the three files
From i, j, k = 1 until 20
    If i <= 20 AND east[i] Is min(east[i], midwest[j], west[k])
        Save east[i]
        Increment i
    Else If j <= 20 AND midwest[i] Is min(east[i], midwest[j], west[k])
        Save midwest[j]
        Increment j
    Else If k <= 20 AND west[i] Is min(east[i], midwest[j], west[k])
        Save west[k]
        Increment k
Repeat

This process is for collecting your thoughts into something more formal than just a list of requirements. It helps you write code without the need to meet syntax and semantics rules for any specific language, so you're constrained only by the rules of logic. All of the "syntax" for the pseudocode above was completely invented on the spot. Any resemblance to an actual …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

strcmp will not do good, u have to use strstr()

If you want to count exact full lines then strcmp() is better. If you want to count lines containing a substring then strstr() is better. The two accomplish different goals.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're vastly overcomplicating trivial stuff and ignoring important stuff. Compare and contrast your code with this:

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

#define MAX 3
#define LEN 100

char **func(void)
{
    char **ptr = malloc(MAX * sizeof *ptr);

    /* Always check malloc for failure */
    if (ptr) {
        size_t i;

        for (i = 0; i < MAX; i++) {
            ptr[i] = malloc(LEN * sizeof *ptr[i]);

            /* Leave a null pointer if malloc fails */
            if (ptr[i]) {
                /* Always check input for failure too */
                if (fgets(ptr[i], LEN, stdin)) {
                    /* Try to shrink wrap the memory to the string length */
                    char *temp = realloc(ptr[i], strlen(ptr[i]) + 1);

                    /* Take care not to lose the original pointer on failure */
                    if (temp)
                        ptr[i] = temp;
                }
            }
        }
    }

    return ptr;
}

int main(void)
{
    char **str = func();
    size_t i;

    for (i = 0; i < MAX; i++) {
        if (str[i])
            puts(str[i]);
    }

    /* Don't forget to release your allocated memory */
    for (i = 0; i < MAX; ++i)
        free(str[i]);
    free(str);

    return 0;
}

On top of actually working, my code also checks for error cases and handles them gracefully. Your code would probably crash and burn under those same cases.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

if i connect with server with username pass which is hardcoded then if someone reverse eng. it he will get userpass how to tackle that??

Well, you can't defend against proper reverse engineering completely, but a combination of secure strings, obfuscated assemblies, and a non-hardcoded authentication key along with the credentials (such as one generated from a license code) would go a long way toward making it much harder to crack.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Look at the link I gave you in my first reply.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Time complexity doesn't change, but the overhead of individual operations changes noticeably between array indexing and link chasing.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not James :/

That's a good thing, because then Daniweb would crash due to overflowing awesome. ;)

~s.o.s~ commented: Haha, I like that ^_^ +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The concept is sound, but super inefficient due to the overhead of chasing pointers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but my question is that like i have i/p a binary number say, 1010 (10 in decimal), then what will be its ascii which ahould be in o/p ?

I'm assuming the input is four characters here, the string "1010", so you'd need to convert that to an actual decimal value. Then that value can be stored in a register and used to output the ASCII character corresponding to the decimal value 10 (a line feed).

I get the impression that you're confused about numeric representations. 1010b, 10, 12q, Ah, they're all the same thing. The only difference is how they're represented on output for a human reader. The computer only sees 1010.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For communicating with a server, I'd probably start with a web service. The server exposes a WSDL which the not-keylogger connects to and calls methods on. The only issue with that in my experience is the relatively hard coded nature of web service references in the client.

If the WSDL is basically static then all is well and you can follow tutorials, but if it could change and needs to be arbitrary in the client, you can't conveniently use a web service reference (at least you couldn't the last time I wrote something like this and did the research). So in the past I've used a little helper function that lets you hit an arbitrary WSDL:

WebServiceProxy.CallWebService(
    wsdlUri, 
    "NotKeyLoggerService", 
    "SaveLoggedData", 
    new object[] { loggedData, screenshot });

I know you didn't ask for code, but this helper isn't obvious, so I'll give it to you anyway:

using System;
using System.IO;
using System.Net;
using System.Text;
using System.CodeDom;
using System.Xml.Schema;
using System.Reflection;
using System.Diagnostics;
using System.CodeDom.Compiler;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Security.Permissions;
using System.Web.Services.Description;

namespace Proxies {
    public static class WebServiceProxy {
        /// <summary>
        /// Calls a web service method with default credentials.
        /// </summary>
        /// <param name="wsdl">Web service URL.</param>
        /// <param name="serviceName">Name of the web service containing the desired method.</param>
        /// <param name="methodName">Name of the method being invoked.</param>
        /// <param name="args">Possibly empty array of method arguments.</param>
        /// <returns>The result of the method as an object.</returns>
        /// <remarks>
        /// If the method has a return type of void, the return …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

10 in binary or 10 in decimal? In binary 10 is 2, which gives you the ASCII value for the control character STX. Really all you need to do is get the integer value and then treat it like a character. To be strictly correct with 7-bit ASCII, make sure that any significant bits beyond the 7th are cleared.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, the specific syntax you posted is a GCC extension. but C99 does support variadic macros with more or less the same syntax as variadic functions. The big difference is how the argument list is retrieved (__VA_ARGS__ for C99 and args for GNU).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Technically it's not a constraint violation so the compiler isn't required to produce a diagnostic message. At best you'd get a warning for a persnickety compiler. For example, Comeau gives me a warning under default settings, but Pelles C doesn't except for the highest warning level. Visual C++ 2010 doesn't even give the warning with /Wall.

Welcome to C, where the compiler won't stop you from doing the majority of bad things. You actually have to know the language and program carefully. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Accidentally I deleted the ACcount ...

How do you accidentally delete your account? It's intentionally a chore to reach the point of no return; you'd have to be intent on permanently deleting the account.

Is there is noWay?

I'm going to go with "there's no way".

We could technically do it with manual edits to the database and memory cache, but the risk involved is far too great. I'm not keen on potentially boogering up all of Daniweb just because you didn't read the many warnings on the path to deleting your account. Sorry.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure I understand the question. You can reset your password from the login popup, and the only way that wouldn't work is if you no longer have access to the email address assigned to the account.

Nevermind, I see what happened now. As the warnings clearly state when you try to delete an account, it's not a reversible process. Sorry.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The the result were the same, why would we have both %d and %c specifiers? If you use %d then the value of ch is interpreted as an integer and the value 23 is displayed. If you use %c then the value of ch is interpreted as a character and the character representation of that value (a control character in this case) gets printed. Because there's not a good graph for the character, you're probably getting whatever decent facsimile your command shell can come up with.

Try changing the value from 23 to 65 for a more obvious test of what's happening.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd like to say beer but they're a bit fussy about you drinking in the office...

That's what telecommuting is for. :D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is an excercise for you to learn. Being given the code only teaches you to beg for freebies.

It's not a difficult exercise, please make an honest attempt and then if you have problems feel free to ask about them.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Dude, go read a book on C. You're asking for something so trivial that I can't imagine anything other than total ignorance as the cause. This forum is not for holding your hand and teaching you from scratch.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You're correct, in a manner of speaking. The problem is that you haven't told the recursive chain higher up that the desired leaf was deleted. What happens if by deleting a leaf, you've created a new leaf? And what happens if that occurs all the way up to and including the root of the tree?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are you asking what we snack on while coding, or what we eat in general? What I eat in general is mostly a healthy diet of whole foods. Staples include:

  • Tea
  • Coffee
  • Oatmeal
  • Peanut butter
  • Cheese
  • Chicken
  • Veggie burgers
  • Frozen Fruit
  • Frozen vegetables
  • Greek yogurt (full fat, of course)
  • Almonds (ideally cinnamon roasted)
  • Spiced Rum
  • Scotch

I'm not a big snacker anymore, but crackers and dry cereal (without milk) would be my go-to snacks while gaming or coding. I like salty things, sweet not so much. :)

<M/> commented: i don't see how alcoholic drinks or veggie burgers are good for you... +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Moved to VB.NET forum.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i need to pass the variable inside the function as argument...

Okay, then do it. You wrote the functions right? So you know how to define parameters and pass arguments, right? You know I'm not going to do it for you, right?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes.

AndreRet commented: lmao, okie dokie. :) +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then just store that value in another variable:

int last = n - 1;

Or if you insist on using an unnecessary level of indirection:

int last = n - 1;
int *plast = &last;

I think I understand what you want, I just don't understand the point of it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is actually an amusing exercise, but if you can really only use one loop then you'll need to employ a trick of two that technically involves an implicit loop. Since you're essentially working with a 2D grid (ie. rows and columns) at least two loops are necessary to get the job done.

For example, in this solution the implicit loop is established using setw() and setfill():

#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
    int n = 5;

    for (int i = 1; i <= n; ++i) {
        cout << setw(n - i) << setfill(' ') << "" 
             << setw(i) << setfill('*') << "" 
             << endl;
    }
}

Of course, that doesn't work for you (intentionally) because it doesn't include an if statement, but it's an interesting exhibition of ostream manipulators.

The first thing I'd suggest is to verify that you can't use nested loops, because a single explicit loop is somewhat tricky and I'd call it a more advanced exercise because of that restriction.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't understand the requirement. n already has the number of items, so to get the last index all that's necessary is to subtract 1 from n. Theres no need for a pointer that I can see.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can't walk you through it because what you're doing isn't meaningful. size is an instance member, which means you must have created an object somewhere and given size a value that warrants outputting it.

I don't think you should be printing size from printStatic() at all, so my suggestion would be to remove that line entirely. It's already being printed from print(), so what's the point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It really depends on how much of Prata's book you actually learn. It covers pretty much everything you'll use on a regular basis, so if you learn the whole thing cover to cover, you should have little problem with any book on C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No, B is a class, not an object.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Both would be suitable. King's book is more highly regarded by experienced programmers, but having read both, I think as an absolute beginner you may prefer Prata's book.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You try to print size from a static member function, but size isn't a static member. To access non-static members, you need an object, because that's where memory for non-static members is allocated.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Put simply, the point is to enforce a trailing semicolon on calls to the macro without losing the massive benefits of having the macro wrapped in its own scope.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The winner for me is Everquest 2. I started playing at launch (2004) and never stopped. Amazingly enough, the game is still interesting and I put a lot of time into it.

I actually preferred Oblivion to Skyrim

Me too. Maybe it's because I burned myself out on Oblivion and Skyrim really wasn't much of an improvement other than a few mechanics and graphics. The faction quest lines in Skyrim were also a joke compared to Oblivion, so I got bored quickly.

Have you played Fallout 3? That's another Bethesda game that sucked away a lot of my time. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For the decimal digits you can subtract '0' to get the numeric equivalent:

'0' - '0' = 0
'1' - '0' = 1
'2' - '0' = 2
'3' - '0' = 3
'4' - '0' = 4
'5' - '0' = 5
'6' - '0' = 6
'7' - '0' = 7
'8' - '0' = 8
'9' - '0' = 9

'A' through 'F' are only marginally harder. If you don't mind making an assumption about those characters being contiguous (note that this is guaranteed for the digits, but not anything else), you can just subtract 'A'. A more general solution is something like this:

int digit_value(char ch)
{
    const char *digits = "0123456789ABCDEF";
    size_t i;

    for (i = 0; digits[i]; ++i) {
        if (toupper(ch) == digits[i])
            return i;
    }

    return -1; /* Or any decent "not possible" value */
}

Now you'll have the individual pieces, and it's only a matter of pasting them together. You can use basic arithmetic or bitwise operations, depending on your preference. I'd suggest looking into how atoi() works for further ideas. I'd show you how to do it, but you'll learn more by working a bit. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is homework. What was your answer to the question? It has to do with how signed and unsigned types interact.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Have you tried searching the forum? We regularly get people trying to install a Model T engine (Turbo C) in their 2012 Ferrari (modern Windows OS).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But here i have defined MAX one time only and it will get substitued by 5 before compilation begins.So which one is better?

Neither. If you're comparing a constant with a constant then you should just strip away the test entirely because it's not dependent on runtime values, or replace it with conditional inclusion:

#if MAX == 5
    /* Do this */
#else
    /* Do this */
#endif

Otherwise you're just saying "always do one part of the if statement, but I still want the overhead of the test". It's silly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

FWIW, use the sha256 hash algorithm if you want to generate a REALLY unique hash value.

A cryptographically secure hash is far too slow and heavy for most hash table applications. When working with hash tables you want the fastest possible hash algorithm that produces the fewest collisions for the expected data. Collisions are easy to resolve, and they only become an issue when there are so many that the resolution method begins to overwhelm the primary lookup.

So far, there are no collisions detected, anywhere! If you do detect one, publish it - you will gain instant internet fame! :-)

Sorry, but in the context of hash tables it's easy (even trivial) to create a collision unless you design a perfect hash for that specific application. Keep in mind that the hash is being munged to fit into the range of table indices. While SHA-256 may not produce collisions when unrestricted, you'll be bombarded with collisions the instant those hashes are forced into a [0,N] hash table, where N is significantly smaller than the upper range of the hash. This is the basic pigeonhole principle.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I want to know the reason why it is not working????

Because it's syntactically and semantically invalid C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but I have no idea what N0$ for example stands for

It clearly stands for the digit '0' in morse code. The dollar sign is just a character in the label name, nothing more. You access it like any other label/variable/identifier. Which assembler are you using?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I thihnk a B.S. in computer science would look better on a resume than information technology.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Quick survey, are you guys liking Visual Studio 2012?

I've only seen a bit of it over the shoulder of a coworker who's playing with it. There seems to be a "dark" mode that I really like, and the interface is less busy, which is good. There are a few odd quirks, but that might just be how my coworker set things up.

it kind of lags a bit at start up.

Visual Studio has favored doing most of the time consuming prep work on startup rather than ad hoc to make actual work respond faster since I think the 2003 version. It's annoying if you find yourself closing and opening it constantly, but otherwise I think it helps. Though it doesn't help with the perception (and reality) that Visual Studio is a very heavy piece of software.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@haw03013

Bullshit

What an insightful way to bump a year old thread. Can you elaborate any?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you know what the storage classes are and what they mean then it's fairly obvious that they're nonsensical when applied to function parameters. What semantics where you expecting?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I guess my question should be "Why is it undefined?".

I'll raise your question with a counter question: what's stopping an implementation from using completely independent allocation pools and mechanisms for new/delete versus new[]/delete[]?

++K;
delete[] K; //Does that delete all instances of F?

No, that should crash because you're trying to delete a pointer that's different from the one given to you by new. If you didn't increment K then it would correctly free the memory, and you'd need to take into consideration that F and K both alias the freed memory.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need a line break between #else and switch(nAbilityOption).