deceptikon 1,790 Code Sniper Team Colleague Featured Poster

draw() looks like an event handler. What object and event is it attached to? Since it only accepts EventArgs, you don't have access to a Graphics property. So unless your event handler is malformed and should be taking something like a PaintEventArgs, you'll need to grab the Graphics object from the control itself.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There are many ways to do something, and I've always found the four line approach to removing a newline to be excessively verbose. As such, my favorite method of removing a newline is this:

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

int main(void)
{
    char buf[BUFSIZ];

    while (fgets(buf, sizeof buf, stdin)) {
        buf[strcspn(buf, "\n")] = '\0';
        printf("'%s'\n", buf);
    }

    return 0;
}

In the above code, buf[strcspn(buf, "\n")] = '\0' will assign to the index of the newline if it's present, or the index of the null character at the end of the string if it's not present. So either you're overwriting the newline or it's a no-op by replacing a null character with another null character. This trick turns the removal of a newline at the end of the string into a one-liner.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You select the framework version in your project properties. But if you use an installer then it will be able to point out missing prerequisites, which include the framework version. I get the impression that you're just copying the executable around.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Let me know if it happens again and you're absolutely sure you didn't accidentally bump the button twice.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

okay so please compile my above program in c++ broland compiler

Why should I have to make my system match yours? That's stupid. Should I also install the same operating system, applications, and use identical hardware to ensure that I get the same results as you? Why not just mail your computer to anyone who needs to run your program, because that's the restriction you're putting in place with your suggestion.

I have a better idea. How about we just not bother helping you at all? That's a lot easier than acquiring the compiler you have, installing it, and then working around whatever other exceptions are involved in making your craptastic code compile without properly fixing it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

my code is totally correct ...because i compile and then post here!

Then your compiler is broken, because it's accepting nonexistent headers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think the availability of Android on different brands make it more appealing to me.

It's quite the opposite for me. Android is so fragmented that regardless of whether the OS is good or not, the variance in hardware makes it difficult to find something that works worth a damn. That's precisely why I chose to purchase an iPhone: I was sure it would work, and that's what I want in my primary phone.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll be committing a fix for this display bug shortly. Pending Dani's approval it should be resolved in the next push to production.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can still see cases where you have to validate the string though. If someone enters 'a' and you convert it to base 10 strtol() will return 0 since the conversion failed but you dont know if the conversion failed or if the user entered 0.

You're only looking at the return value. If that were the case then I'd agree that strtol() is almost as useless as atoi(). However, taking into consideration the second parameter, you can completely validate and convert all at once, then just check the results to see if there were any problems:

#include <cerrno>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string line;

    while (cout << "Enter a number: ", getline(cin, line)) {
        long value;
        char *end;

        errno = 0;
        value = strtol(line.c_str(), &end, 0);

        if (end == line.c_str()) {
            cout << "Not a number\n";
        }
        else if (errno == ERANGE || value < INT_MIN || value > INT_MAX) {
            cout << "Value out of range\n";
        }
        else {
            cout << "Converted value: " << (int)value << '\n';

            if (*end) {
                cout << "Non-numeric characters detected at '" << end << "'\n";
            }
        }
    }
}

A lot of code will just pass NULL as the second argument, but that limits error checking potential. There are four cases I can think of at the moment:

  1. The end pointer is the beginning of the string, so no conversion occurred.
  2. The end pointer is not the …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Wildcards are interpreted by the shell before your program gets a chance to touch them. If you want them passed as literals, then escape them so that they're not interpreted as wildcards:

$ python ./arch.py install \*
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The atoi() function will convert a char* into the int that it represents.

Unless it doesn't represent an int, in which case you'll invoke undefined behavior. Please forget that atoi() exists, it's totally pointless because you're forced to validate the string before passing it. The safer alternative, strtol(), does that validation for you on top of also performing the conversion you want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My comment was in general, not directed at anyone in this thread. Though there are certainly many levels of craziness when it comes to preference. Some people are more reasonable, and others are irrationally stubborn.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Assuming the time part of your date is consistent (such as midnight), it's a simple check against getdate():

"select * from usernames where [Username] = '" & TextBox2.Text & "' and [Password] = '" & TextBox1.Text & "' and [ExpiresOn] >= getdate()"

You might also consider using parameterized queries instead of string concatenation for security reasons (and to make the query easier to read).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's both funny and sad the kind of ire people can have over an operating system debate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon I had responsiveness issues on my S3. Turns out it was due to Samsung's crappy TouchWiz interface. If you flash it with a basic Android ROM it's snappy as hell :) (Bit like Laptops you buy form superstores that come bogged down with all their branded crap)

My responsiveness issues relative to iOS have been with straight Android, as recent as ICS. So while you're certainly right that manufacturers (Samsung especially) have been egregious with their crapware, that's not always the answer when someone mentions UI lag.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Obfuscation is quite a common practice, especially in .net where disassembly of libraries is incredibly easy.

Obfuscation only deters a casual reader. Anyone who's seriously interested in the code will have only a little more difficulty figuring it out from an obfuscated disassembly. Further, no professional in their right mind would manually obfuscate code rather than take advantage of a tool.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

According to the manual WriteLine() returns void, you can't assign that to answer[i].

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pointers are built-in types, they don't have constructors per se. If you want your ppointers to be null, make them null explicitly.

student *head = 0;
student *tail = 0;

Assuming those pointers are members of another class then you can certainly use the default constructor to make them null.:

class foo {
public:
    foo(): head(0), tail(0) {}
private:
    student *head, *tail;
};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I prefer the iOS experience. Android has responsiveness issues whenever I use it, and that slight delay seriously affects the experience. Responsiveness issues seem few and far between on iOS.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's not as much a matter of being an Excel expert as it is whether you want to accomplish this from the Excel UI itself or with a third party program. Since this question is in the computer science forum, I'm unable to determine if you're writing custom software to accomplish this (in which case it should go in the appropriate programming language forum) or need Excel scripting advice (where it would best be moved to the Hardware & Software forum).

As far as doing it from Excel's scripting options, it's a relatively simple matter of looping over the desired row and clearing a cell if it compares equal to another. For example:

Sub ClearCells()
    Dim i As Double

    With Sheets("Sheet1")
        For i = 1 To 10
            If .Cells(i, "A").Value = .Cells(i, "B").Value Then
                .Cells(i, "B").Clear
            End If
        Next
    End With
End Sub

This will clear cells in the B column if they're equal to the A column for the first 10 rows in the first worksheet.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Manually? With Excel scripting? Using third party code using an Excel library? Your question is specific as far as what you want to happen, but vague in terms of how you're looking to accomplish it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

what is the PFO page...?

http://www.programmingforums.org/

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

fgets() includes the newline that terminated input for a successful call. If it's there you need to remove it:

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

char *fgets_trim(char *s, int n, FILE *in)
{
    char *p = fgets(s, n, in);

    if (p) {
        s[strcspn(s, "\n")] = '\0';
    }

    return p;
}

int main(void)
{
    char s[BUFSIZ];

    if (fgets_trim(s, sizeof s, stdin)) {
        printf("'%s'\n", s);
    }

    return 0;
}

However, note that the newline is important information. If it's not present after fgets() returns then that means you may have read a partial line. If you continue to push through with your normal logic then you may get garbage results. So take care in just automatically removing the newline without considering other error handling strategies.

A more thorough approach might be with a dynamically allocated string that grows to meet input needs:

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

char *dgets_trim(FILE *in)
{
    char *p = NULL, *temp;
    size_t size = 0, end = 0;
    char buf[BUFSIZ];

    while (fgets(buf, sizeof buf, in)) {
        size += strlen(buf);
        temp = (char*)realloc(p, size + 1);

        if (!temp) {
            break;
        }

        p = temp;
        strcpy(p + end, buf);
        end = size;

        if (p[end - 1] == '\n') {
            p[end - 1] = '\0';
            break;
        }
    }

    return p;
}

int main(void)
{
    char *s = dgets_trim(stdin);

    if (s) {
        printf("'%s'\n", s);
        free(s);
    }

    return 0;
}

But ultimately your problem is the trailing newline after each fgets() call. Remove that and your output will look …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Both...not at the same time though. I'm a tea snob, but I also love a nice cup of joe.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But without it, I can safely say the min numbers of nodes is 4, correct?

If you're changing the rules then remove the other constraint and the minimum number of nodes is zero.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

May I ask why you need to convert that code to C? Seems suspicious.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

wat confused me was least deep leaf has depth 2. Why so, it should be depth 3 if height is 3.

It means the leaf that's not at the deepest level (level 3, matching the height). In this case, 7 in the following tree is the "least deep" leaf. The height is 3, the least deep leaf is at level 2, and the tree is as full as it can be, so it's the answer to part a of your question:

             1
      2             3
  4       5     6       7
8   9   a   b c   d

That's 13 nodes, on the assumption that the height excludes the root. However, if the root is at depth 0 then that's more of a safe assumption than usual. For the minimum you need to recognize that the tree isn't required to be full or complete, and the smallest tree possible while maintaining the two restrictions (a height of 3 and the least deep leaf at level 2) is some variation of this:

             1
      2
  3       4
5

The height is still 3, the least deep leaf is still at level 2, and the tree cannot have fewer than 5 nodes without breaking one of those two invariants.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ask him to draw it for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

was it 3 hours before the big update you did a while back or was i just plain wrong?

Nope. If memory serves me it may have once been 15 minutes, but was never more than 30.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Flat html isn't to bad in my opinion.

Obviously I don't know anything about your experience, but this statement suggests you've only worked with what I'd consider to be "small" web pages. Any small program isn't too bad, but it gets out of hand almost immediately.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sometimes it takes several seconds to fully submit the post and refresh the thread. How long did you wait before concluding that the post was not submitted?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

See some interesting code here.

When experts in a language try to write impenetrable code. ;) IOCCC entries are actually beautiful in a perverse way because it takes a great deal of skill and effort to obfuscate what are normally straightforward programs into something that requires expert-level abilities to figure out.

Compare this with plain bad code, which is ugly because the lack of skill and effort is apparent at a glance.

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

Does anyone have an idea what the worst habbit they have seen is?

Zero indentation, no contest.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I've been using Windows 8 exclusively at home for a few months now and haven't experienced any problems in IE, Chrome, or Firefox. The problem you're describing sounds a lot like a zoom issue. Reset your zoom (usually with something like ctrl+0) and see if that fixes the "awkward".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but some fool is looking for help to run the code shown

Thanks for notifying us of a thread that fell through the cracks.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So the 2* x + 4 is the value that is returned to the function (fx), right?

Yes.

The int does it stand for integer as in the numbers 1,-1,2,-2,2,-3,...?

Yes.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd like to think that the more experience one gains with reading and writing code, the less these little details matter. A modicum of common sense in the coding style and overall consistency is what matters.

This attitude is especially important if you plan to step into the professional world, because you'll be asked to compromise when designing style guidelines for a team or even throw out your personal style entirely to conform to an existing style guideline.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

When I hear function I think about maths, with f(x)= 2x + 4.

Computer science and programming are rooted in mathematics, so that's not a bad way to approach the concepts. Taking your example, it translates easily to C++ like so:

int f(int x)
{
    return 2 * x + 4;
}

And by providing x, the caller can execute the function:

int main()
{
    std::cout << f(5) << '\n'; // 2 * 5 + 4
}

What is a function's caller?

The code that executes a function, provides arguments, and accepts the return value is the caller. In the example above, main() is the caller for f(), and f() is the callee.

PrimePackster commented: Worth it! +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Turn anything that looks like this:

while(ch!='\n')

Into this:

while(ch != EOF && ch!='\n')
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The date() function takes two arguments. The first argument specifies the date format you want the timestamp to be converted to. The second argument specifies the timestamp that will be converted. Without the second argument, how does the date() function know what the date is?

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

Please post a small sample of your database file.

edit: And fix the following:

if(ch==alphabet)            /* if found then increment the number of bytes and check the size
{                              of a given entry */

The opening brace is caught up in your comment. I assume you fixed it in the real code, because otherwise it wouldn't compile at all, much less create an infinite loop at runtime.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I considered forcing you to post the actual error message rather than the error code because most people haven't memorized all of the codes for Visual C++. But if you prototype your min() function, you'll fix those two and be left with the rogue semicolon in one of your output statements.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For starters, if you're ever going to expect to compare ch against EOF, then you must declare ch as int. You'll notice that all of the character I/O functions work with int, and the reason for that is EOF.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Do i just have to put a * instead of + and prodcut instead of sum? If so it didn't run.

Nope, you also need to define and initialize v1 and v2. Then it'll work:

#include <iostream>

int main()
{
    int v1 = 2;
    int v2 = 5;
    std::cout << "The sum of " << v1 << " and " <<v2 << " is " << v1 * v2 << std::endl;
    return 0;
}
Kareem Klas commented: Thank you! It helped me alot. Weird that the book didn't say me to define and intialize v1 & v2. Really thanks alot! +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I don't know about you, but the error I got was complaining that your node structure is incorrect. The next node should be a pointer to node, not a pointer to int:

struct node{
    int id;
    node *next;
};

I didn't look any further since that right there was a deal breaker for the program. Apply the fix and see if it helps.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Echo the value of $dtime and see what its value is.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Specify a section. The three most common are:

  • 1: General Commands
  • 2: System Calls
  • 3: Library Functions

So if you want the open() function, you'd search using man 3 open

fyra commented: thanks. +0
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does that clear things up?

Yes indeed. That has nothing to do with Daniweb (not 100% on that, but I'm reasonably sure). It's your browser remembering previous input. I don't get any options because I haven't flagged any posts. ;)

The other issue can be seen by logging out of your account and you read the message, it says its an error :)

I was actually confused about the first issue and kind of ignored the second. I'll look into it.

edit: No issues logging out from this thread. What pages are you viewing when it happens?