deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm sure everyone is familiar with this random piece of disassembled code. :rolleyes: Do you have an actual question that I'm not likely to answer with "go read a book on assembly language"?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does it help to make a class object as a pointer?

In your code it doesn't matter, but there are a number of reasons you might want or need a pointer. Dynamic allocation comes immediately to mind as a case where you need a pointer.

and also the code crashes when it runs, why cant i use int *k to hold the value?

A pointer has to point somewhere. If you don't explicitly make a local pointer point somewhere then it points to some random address, and any attempt to dereference will likely blow up on you (or worse, not blow up right away).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

See this tutorial for details on writing a hash table. As far as extracting each item in the list for adding to the dictionary, it should be a simple cursor-based traversal:

Dict CreateDic(void)
{
    void AddDic(Dict*, student*);

    LIST cursor;
    Dict dict;

    for (cursor = 0; cursor != -1; cursor = VH->head[cursor].next)
        AddDic(&Dict, &VH->heap[cursor].stud);

    return dict;
}

AddDic() would generate the hash and add a copy of the student to your hash table. Note that I'm making quite a few assumptions in that CreateDic() because you didn't provide all of the necessary details. But it should be sufficient to exhibit how you might traverse the list.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you please PM me since I can't PM anyone here.

You can post though, so do that. It's actually preferred as more people will be able to help when the information is publicly available.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And I suppose you were hoping someone would tell you how to do it? Maybe even do it for you? Sorry, but here on Daniweb we expect a modicum of effort from you, so you'll generally get little sympathy for playing the clueless card.

Given your previous threads, I find it difficult to believe that you aren't able to write a simple loop, take string input, or figure out how to change the case of a single character. Hell, you could write an empty program with some comments on the requirements just to get a starting point:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    // Read a string
    // Loop over the string
    //     - Replace each character with its lower case equivalent
}

That's really all this program is.

So...please try again, and come back when you have something to show for your effort. I'll be happy to answer pointed questions, but "I don't know anything" is both too broad of a subject for me to cover concisely and it discourages me from helping you because you come off as a time vampire.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

hey guys so i was thinking of how i would make a program that would state the alphabet from a-z in capitols then the program would change it all to lower case one at a time.

And what did think?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Your question is too vague.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Ah, that's true. I'm always mixing up C# and VB.NET in my head (usually by including C#isms in VB.NET and getting frustrated when it fails). ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Are all purple dots invisible when Invisibility mode is on? I don't see any dots of any color.

Yes, the online indicator respects the invisible option.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am wondering if the Builder pattern would be a candidate for being applied here?

Maybe you're thinking of doing it in a cool way (if so, please share!), but I can't think of any benefit to the Builder pattern that would justify the added complexity. Of course, I'm not a fan of design patterns in the first place, so I'm a little biased. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

just convert it

I'm not going to do your work for you if I'm not getting the grade for it. If you want help with a specific error or problem, give us details about what the error is, what you expect, and what you get that differs from your expectation.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but the problem is in how do i convert all this data

You don't. Pretty much the only C++isms the code uses are in I/O. Replace cin and cout with scanf() and printf() and you're done except for minor syntax errors that are trivial to fix.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Post more code.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

C++ conversion of this C snippet for a simple interactive menuing system.

The code shows three files:

  • menu.h: The header file for the menu class.
  • menu.cpp: Implementation of the menu class.
  • main.cpp: A sample driver that uses the library.

The menu library is fairly generic in that you can provide a format string of menu options and possible matching input values. See main.cpp for an example of how to use it. Note that C++11 features are used in this code.

mike_2000_17 commented: Cool! +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I imagine it would be a good job for experience as you're likely to be doing most of the grunt work.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm set to invisible, or is that irrelevant? :)

If you're invisible then you get no dot. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Um...what?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only real problem I see in that line is your query isn't correct. You still need to add single quotes in the query to make string values SQL strings. It helps to copy the string verbatim into Management Studio (or whatever database utility you use), replace the VB.NETisms and run it to verify your SQL syntax. For example, your query would look like this with some dummy data:

SELECT * FROM Security_Ques WHERE Username = someuser and Ques_Index = 0 and Answer = blahblahblah

Looking at it this way, it's obviously incorrect because your strings aren't quoted.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So after creating an instance of form2 you just assign the text from form1.textox1.text to form2.label1.text

Only if the control is explicitly made public in Form2. By default new controls added through the designer are private (as they should be!), and in a code review I'd question making them public.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I didn't realise that expletives are permitted if not filtered out by the 'filter-thingy'. :)

On this one I'll disagree slightly with Dani because a blacklist isn't a complete solution to matters of censorship. The profanity filter is a good measure of common words we want to disallow, and if a common word isn't censored, like "shit", then it's safe to say we allow it. Obviously if a word is filtered, like "fuck", there's no doubt that we disallow it. ;)

However, that doesn't mean the mod team can't deliberate on an uncensored word and vote that it's a violation of Keep It Pleasant. That word then may or may not be added to the profanity filter depending on how likely we suspect it to be used again in the future. After all, it's not practical to build a gigantic blacklist of every word that someone may find offensive. But infractions based on an uncensored word shouldn't be done without team consensus.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Does anyone have any more experiences that they wouldn't mind sharing?

Mine is a cynical view after having been a system administrator and working with them in many different companies as a consultant. I typically don't expect sys admins to be experts even in the systems they administer. My first foray into the IT field put me in the sys admin position at a reasonably large corporation, and while it was a fabulous learning experience, it highlighted for me that one can do the job without really knowing what you're doing. Further, I regularly go above and beyond as a consultant and end up teaching the system admins of my clients things that I personally think they should already know[1]. And these are not small companies we're talking about, some of my clients are among the largest in the United States or are worldwide. ;)

Ultimately you'll have to satisfy the hiring managers when it comes to skills and experience (which turns out to be easier than the requirements on paper suggest), but my personal opinion is that connections will help far more in getting a job. While the lesser things like tech support and IT grunt will certainly give you experience in the techical and social areas, you'll also meet people who can give you a leg up in advancing to the job you really want.

[1] One thing that consistently comes up and surprises admins is that network shares and the attached physical folder have separate …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I heard Java's syntax is similar to C

It's derived from C, yes. Java as a language is easier than C, in my opinion, but as soon as you throw in the gigantic standard library it gets harder.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It seems that the only reason it was deleted was out of fear of offending riahc3.

Agreed. Since no rules were broken, I'll chalk it up as a lapse in judgment (mods are human, after all) and restore the post.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

are the other languages any easier than c?

Depends on which "other" languages you're thinking about, but in general, yes. C is a simple language, but it's not easy because it doesn't hold your hand. You need to think about and manage a lot of low level things to write good C.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Define a property in Form2 that will hold that string, then assign to it and refresh()/invalidate() the control in Form2 whenever you want (ex. in the validated event of the textbox in Form1). For example, in Form2:

public string MyText {
    get { return textBox1.Text; }
    set {
        textBox1.Text = value;
        textBox1.Invalidate();
    }
}

And in Form1 (assuming a Form2 object has been created):

private void textBox1_Validated(object sender, EventArgs e)
{
    _form2.MyText = textBox1.Text;
}

Edit: My bad, I thought this was the C# forum. But the solution is identical, just use VB.NET instead of C#. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The type of file is irrelevant if you're treating it as a sequence of bytes. As long as you don't lose any packets in the transfer, the .exe will be reconstructed correctly and will run on a matching OS.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What about last part"how much you will pay based on the full amount of the items you want to buy." ?

It just means that the total amount prior to discount is what dictates the discount.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If the total amount is greater than $399, multiply it by .9 to get the total after a 10% discount. Otherwise, if the amount is greater than $199, multiply it by .95 for a 5% discount. Otherwise, don't make any changes:

// Apply discounts
if (total > 399)
    total *= .9;
else if (total > 199)
    total *= .95;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think it's a good choice in general, but I know nothing about you, so I can't say if it's a good choice for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

except what deceptikon posted :(

Sadly, that happens a lot. Today at work I was getting frustrated because a client just didn't seem to grok my explanations about how macro translation in some of our software's text areas worked... :(

Like I said, you will never use them (as in mattboy64). ;)

Yeah...want to know how many times I was told I'd never use something when I was a beginner that I use often now? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but I can give you the snippet that actually fails

Well, the vector itself is a local variable, so that helps. Try tracing nextToken(), the constructor for Token(), type(), and strval() to see what kind of memory accesses are happening. You might be dereferencing a dangling pointer or an array out of bounds, or something.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You have a lot of problems, but the particular problem in edelete() that you're asking about is this:

if((e3.name,dname)!=0)

The code is legal, but you clearly meant to write this:

if(strcmpi(e3.name,dname)!=0)

Anyway, out of the goodness of my heart, I'll fix your code and make it portable so that you can learn what good code (well, semi-good) looks like and hopefully emulate it in the future. I'll keep the code simple and use your basic design except for one modification: instead of a binary file I've serialized to a pipe delimited format in a text file. The more experience I get, the less inclined I am to use binary files, they're often more trouble than they're worth.

Here's the code:

#include <cctype>
#include <fstream>
#include <ios>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>

struct Entry {
public:
    std::string name;
    std::string address;
    std::string city;
    std::string state;
    std::string phone;

    std::string serialize() const;
    void deserialize(const std::string& s);

    friend std::istream& operator>>(std::istream& in, Entry& obj);
    friend std::ostream& operator<<(std::ostream& out, const Entry& obj);
};

void AddEntry();
void FindEntry();
void ModifyEntry(bool delete_entry = false);

int main()
{
    bool done = false;

    std::cout << "\n\t\t\tTELEPHONE DIRECTORY";

    while (!done) {
        int choice = 0;

        std::cout << "\n\n\n\t\t\t*** MENU ***\n";
        std::cout << "1. NEW\n";
        std::cout << "2. SEARCH\n";
        std::cout << "3. MODIFY\n";
        std::cout << "4. DELETE\n";
        std::cout << "0. EXIT\n\n\n";
        std::cout << "Enter your choice: " << std::flush;

        if (std::cin.peek() == '\n') {
            // Just ignore that can of worms, but allow it without …
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Without looking at your code (because let's be fair, there's a lot of it), my gut reaction is that you've done something somewhere that corrupted the vector. This is most likely due to an out of range access or wayward pointer. So in troubleshooting I'd focus on memory corruption.

Can you shrink your code down to bare bones without eliminating the error? That would be mighty helpful both to us and to you. ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Namespace definitions can be split across multiple files and still have the same name, is that what you mean by "shared"?

// file1.cpp
namespace foo {
    class A {};
    class B {};
}

// file2.cpp
namespace foo {
    class C {};
    class D {};
}

When the project is built, those two namespaces are merged because they have the same name, so concerning membership in the namespace it's as if you wrote it like this:

namespace foo {
    class A {};
    class B {};
    class C {};
    class D {};
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does your display loop look like?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

however it says that it is an implicit declaration of function "main"
and that it is invalid in C99

I'm guessing your main is defined like this:

main()
{
    ...
}

That definition uses a feature called "implicit int", wherein if a type is required such as in the return type of a function, omitting that type will result in the compiler assuming that you meant int. C99 removed that feature entirely, so now you have to explicitly specify the type:

int main()
{
    ...
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You will never use & in printf() unless you plan on printing out raw memory addresses, which you will almost never do.

Never say never. ;) printf() supports a %n specifier that assigns the number of characters written up to that point:

#include <stdio.h>

int main(void)
{
    int n = 0;

#ifdef _MSC_VER
    // Visual Studio disables %n by default and only provides a runtime way to enable it...
    _set_printf_count_output(1);
#endif

    printf("Printing 22 characters%n\n", &n);
    printf("Printed %d characters\n", n);

    return 0;
}

However, that specifier is viewed as a security risk, and some compilers (notable is Visual Studio, as in the example) will disable it.

A string esssentially is a memory address that points to the first character in a group of characters

Noting, of course, that this is a conversion that happens implicitly when arrays are used in value context and it's important to recognize that strings in general aren't inherently pointers.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Of course, you're always welcome to request that a post be deleted. But be aware that unless it's a flagrant violation of the rules, we're likely to reject the request. On the other hand, if it's a simple matter of removing something like personal information from a post, we're generally sympathetic and will edit the post accordingly.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A pointer to T and an object of T aren't compatible types. You can convert Shoe into a pointer, but that seems kind of silly since the member function is being called on Shoe...

Shoe.Load(&Shoe);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The only difference between struct and class in C++ is default visibility. Structures are public by default and classes are private. Other than that they're identical in features and functionality. Use whichever makes more sense to you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i tried posting the code but i am not able to do that .it says my code if formatted incorrectly.......

That error means your code wasn't in a code block. Paste everything in, select it all and hit the tab key. Alternatively, just use the Code button on our editor. It will pop up a code editor box that you can paste your code directly into.

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

do you mean that code

No, I mean this code:

printf("\nreal number:");
scanf("%d",&x.real);
printf("\nImaginary number:");
scanf("%d", &x.imag);

There's no guarantee that you'll see "real number:" before scanf() blocks for input, which means the user will have no clue what the program is waiting for. If you're not ending the prompt with a newline, I'd recommend calling fflush() to ensure that the prompt will be visible at the right time:

printf("\nreal number:");
fflush(stdout);
scanf("%d",&x.real);
printf("\nImaginary number:");
fflush(stdout);
scanf("%d", &x.imag);

why this happened????????

Probably because you're mixing single character input with formatted input. They don't mix well. To see exactly what characters are being processed, just output ch immediately after scanf() returns. I'm willing to bet you'll be surprised.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

all i need is a way to press Q to end the program!

I was going to post this directly, but it turned into something a bit more serious than I originally intended:

http://www.daniweb.com/software-development/c/code/445012/simple-interactive-menu

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I was going to post this in a thread, but it turned into something a bit more serious and may be useful as a code snippet.

The code shows three files:

  • menu.h: The header file for the menu library.
  • menu.c: Implementation of the menu library functions.
  • main.c: A sample driver that uses the library.

The menu library is fairly generic in that you can provide a format string of menu options and possible matching input values. See main.c for an example of how to use it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This smells like homework where you were given everything except the implementation for perfectShuffle(). As such, I'm going to ask that you prove you've made an honest attempt at completing the assignment. Do you understand how a perfect shuffle works? That's the first step, because you can't tell a computer to do something when you don't know how to do it manually.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is how the code looks like:

That doesn't change my answer. But your code is completely broken. Perhaps if you used names that weren't completely meaningless, I'd be able to suggest ways to change the code so that it both compiles and does what you want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

when the code is compiled

What code?

Can u pls tell us the errors the errors to b clarified

WHAT ERRORS?! Do you expect us to read your mind?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Understanding how it (recursion) works is still beneficial, even if you don't plan to use it.

That goes without saying. :)

Given the stack size of most modern day compilers this will not realistically be an issue here.

The default stack size on Linux is about 8MB. On Windows it's 1MB. On OSX it's 512KB. Noting that the stack is used for a great deal more than just your recursive stack frames, it seems like a risky assumption that the stack size on a modern OS will save you from a poor choice of algorithm.

But even if the stack is sufficient or you go out of your way to make it sufficient, that's no reason to pessimize (opposite of optimize) your code. If the recursive implementation doesn't buy you at least a twofold reduction in complexity, and also includes what I would consider a probable risk of stack overflow, that sounds like a losing deal to me.

Besides, realistically C is more often used on systems where resources are very tight, so understanding the tradeoff is important.

I'm not sure what you mean by the recursive growth but I assume you mentioned the "or worse" part to word it for a general case.

Growth, depth, number of recursive calls before returning, whatever you want to call it. For a linked list the depth is linear and corresponds to the number of nodes. Compare this to a binary search tree where the average depth …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

erm i'm using the compiler in quincy 2005?

Quincy is an IDE, not a compiler. It uses MinGW as a back end, which basically amounts to the GCC compiler. GCC supports C99 under that version, as far as I can tell, but you have to turn it on with a switch. I doubt it's turned on by default, so there you go.

Line 19 - scanf("%c",&ch);
This is overkill (reason).

That's a good reason, but I think I can make it more clear how much work is done. This link is an implementation of fgetc() that I wrote (where fgetc() is the back end to getchar()); it's about 10 lines of straightforward and efficient code. Even if you include the definition of fillbuf(), the whole thing comes in at under 50 lines.

This link is the implementation for scanf(), and this link is the format string parsing helper. I'd estimate that all totaled up you're looking at close to 900 lines of code, and it's not exactly trivial. I spent more time writing printf() and scanf() than the rest of the standard library in that project put together. Naturally not all of it will be hit for a simple format string like "%c", but scanf() is undeniably a heavy function compared to getchar().

tux4life commented: Good post. +13