deceptikon 1,790 Code Sniper Team Colleague Featured Poster

operand types are incompatible ("char" and "const char *")

You should use the standard C++ string class. C-style strings are awkward, low level, and easy to get wrong (as evidenced by this thread). However, let's look at the problems in your original code, and ignore all of the wrong advice you've been given up to this point.

This is wrong:

char* arrayMap[5225];
...
mapReader >> arrayMap[i];

Why is it wrong? Because arrayMap[i] doesn't point to memory that you own; you're extremely likely to get a memory access violation at runtime. Memory must be allocated first, but doing that would be awkward, low level, and easy to get wrong (as evidenced by this thread). Yes, I'm intentionally repeating myself.

This is wrong too:

if (arrayMap[i] == "X")

The equality operator doesn't work the way you think it does at a lower level. arrayMap[i] is a pointer, and "X" evaluates to a pointer. Unless the planets align and you get a perfect storm of shared string literals in the compiler implementation and arrayMap[i] was conveniently initialized to "X", this test will always fail.

To compare C-style strings you must compare all characters up to a null character ('\0'). The simplest way to do that is by calling the std::strcmp() function:

if (std::strcmp(arrayMap[i], "X") == 0)

Or, since these are single character tests, you can just look at the first character:

if (arrayMap[i][0] == 'X')

But you can greatly simplify things by using …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you do:
masked_raider = jimmy;
You will see the change you ask !

Um, no. That won't compile because masked_raider is an array; it doesn't support direct assignment. The only way to restore the alias is to assign the address of the first element of masked_raider to jimmy (which may be what you really meant, but accidentally reversed the assignment):

/* Option 1: Implicit conversion to a pointer */
jimmy = masked_raider;

/* Option 2: Explicit conversion to a pointer */
jimmy = &masked_raider[0];

/* Option 3: Weird stuff (not recommended) */
jimmy = &*masked_raider;
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So any title regarding this field guys???

Why don't you figure out what the project will be, then devise an appropriate title? It baffles me how people can take years of college and still be unable to think of something as simple as a title. Did you learn nothing up to this point?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

With three programming courses under my belt will I be able to find a job out there in the real world?

Getting a programming job has less to do with how much you know about programming and more to do with selling yourself. So while I'd say that right now, from the given information, I wouldn't hire you, it doesn't mean you can't find a job.

Do you have any recommendations on courses that I should take?

Apparently you want to be a Java developer, so take any courses you can.

Do you recommend that I take the Java Certification exam after I finish my advanced Java course?

Yes.

My school offers Enterprise Java, should I take it?

Probably, yes.

Do you believe that I can find a programming job right now?

I think you'll find it extremely difficult. Consider joining some open source projects to build experience. You can also use your existing business contacts to get an edge on folks who are just sending in resumes or walking in the door without knowing someone in the company.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So is there a way to say that if the result is less than zero, to recieve a message that you can not draw that amount because you dont have credits (just like in prepaid SIM cards).

Yes. Check the value and put up a message if someone tries to draw more from an account than the current balance. This is what I meant originally by saying "the ideal solution would be to disallow negative values in the first place".

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think that the solution must be different as you gave me.

Sorry dude, but you keep showing me different code as an example of your problem. At this point I have no clue what you want.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, the ideal solution would be to disallow negative values in the first place, but a quick fix would be to take the absolute value of vlera so that it's never negative:

GjendjaButon.Text = "Gjendja: " + Math.Abs(vlera);
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@AD: toupper() and tolower() seem to return int and not char.

That's only to support an argument of EOF (in which case EOF is the return value). If you never expect to pass EOF, such as when it's a stopping condition prior to calling toupper() or tolower(), there's no need to use int. However, your compiler might warn about a narrowing conversion, in which case a cast is justified:

// Option 1: Use int
int foo = tolower(c);

// Option 2: Cast to char
char bar = (char)tolower(c);

Usually the destination is a string, or something along those lines, so the cast is usually the desirable approach for silencing a warning you know is spurious in that specific situation.

And of course, I shouldn't leave without mentioning that the parameter type is int, but the value range is that of unsigned char or EOF. So you generally want to enforce unsigned char on the argument to account for when vanilla char on the implementation is signed:

char foo = (char)tolower((unsigned char)c);

Otherwise you might encounter a weird situation where tolower() and friends do a table lookup using a negative value and all hell breaks loose for no apparent reason. Those are tricky bugs to troubleshoot.

tux4life commented: Thanks for the correction. +13
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

But I like decepikon's suggestion better.

Me too. I shouldn't have to break my code's portability to disable a spurious warning from the compiler. And in this case I don't, but it does involve a configuration for each project. Slightly irritating, but not nearly as irritating as locking myself into Visual Studio or adding ugly conditional compilation just to silence a warning that doen't apply to me in the first place (I know how to safely use the "unsafe" functions).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Warning 4996 is the height of stupidity, so I'll hard disable it in the project settings without any hesitation. Go to your project properties, then uder C/C++->Advanced there will be an option for disabling specific warnings. Add 4996 to that list and enjoy never seeing that ridiculous warning again.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

My problem is after change the value of Masked raider the jimmy changed,but when set jimmy = "not ok";
Masked raider did not change,how to explain it?

When you changed jimmy to "not ok", you pointed it to a different object (the string literal "not ok"). At that point, jimmy no longer aliases masked_raider.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You could build the array up manually using nested explodes:

$fields = explode(',', 'Name: John, Age: 20, Phone number: 12343223');
$result = array();

foreach ($fields as $field)
{
    $kvpair = explode(':', $field);

    if (isset($kvpair[0]) && isset($kvpair[1]))
    {
        // Both key and value exist (expected case)
        $result[trim($kvpair[0])] = trim($kvpair[1]);
    }
    else if (isset($kvpair[0]))
    {
        // Only the key exists. May be an error depending
        // on the application, but a sensible default is
        // to accept it with an empty string value.
        $result[trim($kvpair[0])] = '';
    }
    else
    {
        // $field represents an empty field from the source
        // string. A sensible default is to ignore it, but
        // raising an error works too.
    }
}
broj1 commented: Nice and clean +8
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Well, an obvious first attempt is to loop through the items in the listbox and not update your textbox if the random number already exists:

xhiro = "1301" + numri;

bool exists = false;

foreach (var item in listbox.Items)
{
    if (item == xhiro)
    {
        exists = true;
        break;
    }
}

if (!exists)
    xhirollogariaBox.Text = Convert.ToString(xhiro);

Also one other problem is that I don't know how to prevent another textbox to include numbers, probably that is something like regular expressions or whatever.

If you only want to allow numbers then a numericupdown control makes more sense. But a quick and dirty solution for regular textboxes is simply ignoring non-numeric digits in the KeyPress event:

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = !char.IsDigit(e.KeyChar);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I think in posting only a "portion" of the code, you've edited it into nonsensicalness. Could you post more code, or ideally, a small but complete program that exhibits the problem.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Saying the feature is "contraversial", I think that goes too far.

Note that I called it potentially controversial. I can't say it's controversial when there's no controversy to speak of yet. But given syntax shifts in the past, I can safely say that more than a few people will be vocal about it if it starts to get used regularly in place of assignment or paren-style initialization. ;)

And by "controversial" I mean the usual holy wars about style, not any technical flaws in the feature.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

For those of you familiar with the latest C++ standard, what do you think of uniform initialization? Listening to folks like Herb Sutter, it seems like the intended purpose is to be completely pervasive, which obviously changes the look and feel of C++.

Do you plan on using it everywhere possible? Only in places where narrowing conversions are problematic? Never at all because it's ugly? ;) This seems like the most potentially controversial new feature of the language.

Personally, I'm still on the fence about it. On the one hand it seems ugly and awkward, and on the other there are distinct benefits (especially pedagogical) that would justify the ugliness, iff it's widely adopted amongst C++ programmers and not just the elite.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sir deceptikon how about if I use rich text box what is the code for changing the color?

I especially like how you read the documentation I linked you to that gave details on how to do exactly that before asking. Oh wait, you didn't. :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No bells and whistles, just a quickie millisecond timer showing an alternative to the far less portable clock_t method. A test main() is included, just define TEST_DRIVER as a macro or remove the conditional compilation at the end.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

'Systems' and 'Programmer' sound like 2 separate jobs to me.

They're not. The difference is that a systems programmer will generally write code that sits below userland and provides services to the hardware or OS. This is as opposed to an application programmer that writes programs for users. I've also seen "systems programmer" used in reference to jobs that would better be described as "system administrator". But often the two are intertwined because you won't be good at either without some experience in both.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That means the size of the array is unknown.

That means you shouldn't be using an array. Use a List<> instead, unless this is a homework assignment where the whole point is to learn how to work with arrays. Though such an assignment seems silly since the Array class has supported a Resize() method since .NET 3.5.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

double DivSales::totalCorpSales = 0;

Move this line into the implementation file for your DivSales class.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In any instance, the purpose of the response really seems to be to get the signature displayed in the thread.

Yup, and that's against the rules.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You can do a simple replace on the string:

textBox.Text = textBox.Text.Replace("Yes", "NO")

Changing the color is a different matter. I assume you want to change only the replaced text to red, which won't work unless you're using a rich text box. If it's just a regular text box then you're limited to a global foreground color change. But that can be done by changing the ForeColor property:

textBox.ForeColor = Color.Red

For a rich text box it's a bit more complicated, but you can search for substrings with that control, select them, and then set the color for the selection to red. See the documentation for details.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Yes, you're probably screwed. Consider using source code version control in the future. As a last ditch effort, you can check your autorecovery backup files for the project. It depends on your OS, but the folder is under your documents. For example, on my Windows 7 machine it's:

C:\Users\jdaughtry\Documents\Visual Studio 2010\Backup Files

I wouldn't get your hopes up if I were you though.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but kept getting an error

It's never a bad idea to post the error.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As long as the numbers are recorded as int and not as string or array of chars, getNrDigits provides the correct answer.

cout << getNrDigits(0) << '\n';
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

So, it's not a very good time to be clinging to orthodoxies.

Make no mistake, I'm very open to new concepts and ways of making things better. For example, I have used both Boost.Program-Options and Boost.Parameter because they're good ideas and neat implementations. I've rejected them from a position of experience, it's not just some knee jerk reaction to all things new. In the pursuit of better methods we can't forget that what's worked in the past has worked for a reason.

More like a laboratory, which is just to say that it's a playground with expert supervision.

It seems we see it the same way. Sadly, we're in the minority. Just about everyone I talk to thinks Boost is essentially C++'s version of CPAN.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's just a coincidence.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

O(mn) where m is the number of integers you process and n is the number of bits in an integer.

How did I figure that out? The outer loop is obviously O(n). The inner loop is also obviously O(n) and adds to the outer loop, but the value of n differs from the outer loop, so the complexity isn't O(n^2). O(m) * O(n) (changing one of the ns to m to differentiate them) is simplified to O(mn).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And jrd::Menu menu("A) Option A;A|a;B) Option B;B|b;Q) Quit;Q|q"); is beautiful?

I'd argue that flat file formats (of which that format string is derived) are well understood to the point where it's not excessively krufty. Further, the kruft is limited to the string and doesn't involve what I'd consider to be an unconventional coding style as in the chain of addOption() calls.

But I guess that won't satisfy you esthetic requirements either. ;)

Actually, it looks more conventional, but it's even worse because the macros lie about what's happening. You're not executing an if chain, you're building a menu inside an object. Given the choice of the original code and the macros, I'd pick the original because it's more clear what the intended behavior is.

I know that was a joke, but a serious response may help elaborate on my reasoning. ;)

this pattern of creating the object by several calls like the addOption() function above is a bit weird-looking, but it is very useful.

I don't disagree that it can be useful, but weird looking code should be limited to places where it's genuinely a very superior option because it's weird looking. I'm a strong proponent of transparency at a glance. If I can just look at a piece of code and have a good idea of how execution flows, it's transparent. If I have to linger and mentally parse what's happening then it's not transparent.

That's actually my beef with modern C++ (template …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

menu.addOption( "A) Option A", "A|a", {...

Elegant and nifty, but it's kind of ugly, no? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

can any one help me out to identify this problem?

Do you have a time machine that can take you back to 1990? If not, you'll have to wait until someone happens by who remembers how to use your ancient compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There few major problems with your code (except for mixing C and C++)

Why would you consider mixing C and C++ a major problem?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd love to see implementations of these pattern based solutions. I'm still not seeing any benefit.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

delete (pTempNode->pData); //<=== seems to do nothing
delete pTempNode; //<=== sets pTempNode->pData to NULL

If pTempNode->pData was pointing to something previously allocated by new (not new[]), then the memory will be released. Likewise, deleting pTempNode will release the memory owned by pTempNode and call the destructor. Unless you're setting pData to NULL in the destructor of pTempNode, it may or may not be overwritten with a suitable "invalid" value.

If you don't reset the pointer to NULL explicitly, you cannnot assume that testing it against NULL will have predictable results.

Finally, this line is incorrect for the same reason that your original loop was incorrect:

if (pTempNode->pData == NULL)   

At this point pTempNode has been deleted, you no longer own it. Therefore any attempt to dereference it or use it for anything other than assigning a new address (or NULL) is undefined behavior.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

delete CurrentNode;
CurrentNode = CurrentNode->pNext;

This is the problem. You aren't guaranteed to have a valid pointer even immediately after deleting it. It could be reused just that fast, or more likely, invalidated for debugging purposes. The correct way to traverse and delete a linked list is with two pointers:

CurrentNode = EnemyList->m_pHeadNode;

while (CurrentNode != EnemyList->m_pEndNode)
{
    // Save the current node for deletion
    Node *pTemp = CurrentNode;

    // Move the traversal pointer forward
    CurrentNode = CurrentNode->pNext;

    // Now you can safely delete the saved node
    delete pTemp;
}

// Clean up remaining EnemyList members as needed
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

However, this is a different problem. I reallly hope you could help me with this.

It's a different problem, but my link in your previous thread answers this question too. Please read it.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please see my response to your other thread on the exact same project:

http://www.daniweb.com/software-development/c/threads/445335/convert-list-into-a-dictionary-using-open-hashing-cursor-based#post1919485

The key is the tutorial I linked you to, as it covers a whole lot of everything.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I haven't experienced that. Sometimes when I'm working quickly it takes the highlighter a second or two to catch up, but other than that it works immediately.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

gonna date myself, but isn't time we brought back RTFM?

Most of my knowledge comes from manuals and experimentation. Then again, if you don't want to be like me, don't you dare RTFM! Don't do it! DON'T!!

:D

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but will u tell me compatible code to follwing lines
line nos 36 & 83..

There's a lot going in in those lines, it's not as simple a translation as you probably think. That's why I suggested that you replace the vector entirely with an array.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Can you explain why const keyword works?

It's just a quirk of C++. Put relatively simply, a non-const reference cannot bind to a value because a value cannot be modified unless it resides in a variable. A const reference can bind to a value because it cannot be modified through the reference due to being const. The const reference doesn't need to assume that it's bound to a variable.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

want to convert this program into c language :(

And it only took three posts to get to the root of the problem. :rolleyes: Anyway, you need to recognize that C doesn't have a dynamic array library like C++'s std::vector. So you really have three options:

  1. Find a third party library that does what you want.
  2. Simulate the behavior of std::vector.
  3. Just use an array and make the size "big enough for anything".

#3 is by far the simplest, but it's also wasteful and/or not scalable. However, if this is a homework assignment or otherwise non-critical program then that solution would likely be best.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

There is an error while using 2nd stack. how to debug it.

Start by telling us the error and line. Here, I'll help. This error occurs on line 173:

'void Stack<long double,50>::push(T &)' : cannot convert parameter 2 from 'long double' to 'long double &'

And it has nothing to do with templates, you're passing an incompatible type. push() expects a reference to double, not a double value. So you'll need to either overload push() to take a value, change the reference to a const reference (recommended) because you don't modify it, or create a temporary variable to pass.

The recommended fix looks like this:

template <class T, int size> void Stack<T,size>::push(const T & j)
{
    if (top == size - 1) {
        cout << "Stack overflow" << endl;
        return;
    }
    nodes[++top] = j;
};
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sounds like a kernel panic and automatic reboot. Are you using Windows? The first thing I do on a new Windows install is go into the startup and recovery options of advanced system settings, then disable the option to automatically restart on a system failure. That way when the fault occurs on startup you can actually look at the error without having to boot into safe mode and look at the core dump file.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I interviewd for a position about 6 months ago and they said they love me as a person and what i could do but I didn't praise the company enough

Wow. Sure, you should be interested in aspects of the company that pertain to you determining if it's a job you want, but if you're expected to praise the company, that's a red flag in my opinion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

@deceptikon nonetheless thanks for the reply

Translation: "I think your answer was worthless, but I'll be polite". ;)

What kind of answer are you looking for? A master's degree is nearly always valuable, but the extra time involved in getting one could be prohibitive for your personal goals and target job.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

How do you organise yourself when working on a project?

It really depends on the project. Some are small enough that strict organization is unproductive or even counterproductive. Others are large/complex enough to warrant full bug and feature tracking system and a formal development life cycle. For inbetween projects a couple of spreadsheets and regular update meetings have proven sufficient.

How do you keep track of where you are?

As noted above, I usually use a spreadsheet of features and bugs. In my experience, too much structure slows down the entire process without providing enough benefit to justify it.

How do you comminicate with your team?

Telephone, email, impromptu meetings, leaning over and saying "Hey you!", and the occasional formal meeting. This question is vague. Do you mean the actual methods of communication or when/why I might communicate with coworkers on a project that we're both involved in?

What is youe experience of communicating with clients?

I'm always in close contact with clients. Actually, I probably communicate more with clients than coworkers on most projects. It's very important to avoid getting too far out of scope.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

gets(rm[i].type);
fflush(stdin);

These lines are in the wrong order. I'll let someone else chastize you over using fflush() on an input stream, because it's obvious that you're using Turbo C++. I'll also let gets() slide, but keep in mind that it's the worst possible choice for string input.

i select 3rd option to see records but the record comes blank i.e. I m not able to see the added record again :( ............ What is the error in my coding regarding this ??

I'm not sure I completely understand your reproduction steps, but option 3 searches for a room index, but the prompts imply that you're searching for a room number. If the room number doesn't match the 1-based index of the room in your array, the search will fail to produce correct results.

Consider a search more like this instead:

cout << "Room #: ";

if (cin >> a) {
    // Find the matching room number
    for (i = 0; i < r; i++) {
        if (rm[i].rmn == a) {
            // Display the room
            cout << "Found room #" << rm[i].rmn << '\n'
                    << "\t* Type: " << rm[i].type << '\n'
                    << "\t* Terrif: " << rm[i].terrif << endl;

            // End the loop early
            break;
        }
    }

    if (i == r) {
        // The loop didn't end early, so no room was displayed
        cout << "Room #" << a << " not found" << endl;
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

i just ask how can i do that program ?

Please read our rules concerning homework, then ask a specific question.

By the way, "How do I do it?" is silly and unproductive because obviously the answer is you think about the problem, devise a solution, and write code to implement the solution.