Narue 5,707 Bad Cop Team Colleague

>it doesnt create a.dat
Are you looking in the right place?

>also how would i switch f from read state to write state?
Flush or seek, and you're good to go.

Narue 5,707 Bad Cop Team Colleague

You're probably thinking of Chinese. Japanese isn't much harder than Spanish, in my opinion, and English speakers generally don't have much of a problem with Spanish.

Narue 5,707 Bad Cop Team Colleague

>i speak french too.
I don't speak French at all. ;) The only two spoken languages I know are English and Japanese.

Narue 5,707 Bad Cop Team Colleague

>Are there some American specific names?
No, but common names in the United States will have a more native sound than uncommon names.

>What is the American version of "Julienne"?
*shrug*

>Why did your family give you a French name?
It could be because of my family's (partially) french ancestry.

Narue 5,707 Bad Cop Team Colleague

Might I suggest "%ls" instead of "%s"?

Narue 5,707 Bad Cop Team Colleague

Often the line that's given in the error is where the error finally breaks compilation. The actual problem is more likely to be up a few lines.

>I'm programming in vs6.0, if it is important..
It's important enough for me to tell you that Visual Studio 6 is one of the poorer C++ compilers. You'd be wise to upgrade.

Narue 5,707 Bad Cop Team Colleague

>undefined reference to `rand_1toN(int)'
rand_1toN isn't going to magically do something. You have to give it a definition.

Narue 5,707 Bad Cop Team Colleague

>My example does probably what the OP requires in simpler terms.
Not really, seeing as how the OP was specifically asking for the usage of std::find in the case of composite data, not a replacement for std::find that does the same thing.

Narue 5,707 Bad Cop Team Colleague

>how can i convert a hex value of a byte (unsigned char) to a short value?
By assigning it, perhaps? :icon_rolleyes:

unsigned char hexByte = 0x02;
short value = hexByte;

Your question betrays a misunderstanding of how numbers are represented in memory. There's no conversion going on[1]. The internal representation of hexByte is assigned to value, so it doesn't matter if you initialized it with a hexadecimal literal, an octal literal, or built it manually using bitwise operators in base 64. The result will remain the same.

[1] Unless you count the extension of the value from a smaller unsigned integer type to a larger signed integer type.

Narue 5,707 Bad Cop Team Colleague

>(*hPtr).style = "abc";
You don't copy arrays like this. You also don't compare arrays with the relational operators either. Further, at this point hPtr doesn't point to anything. You need to point it to an address that you own:

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

int main()
{
    struct house
    {
        char style[40];
        int rooms;
        float price;
    } h, *hPtr;

    hPtr = &h;
    strcpy ( (*hPtr).style, "abc" );
    (*hPtr).rooms = 4;
    (*hPtr).price = 10.0; /*values were used so that printf is possible*/
    printf("%s %d %f\n", (*hPtr).style, (*hPtr).rooms, (*hPtr).price);
    return 0;
}
Narue 5,707 Bad Cop Team Colleague

>Well I mean to say Where could a reference to a function be useful?
Pretty much the same places a pointer to a function is useful. Barring extra restrictions on a reference type (same as references to objects), the two are pretty much identical.

>Especially when declared as a TYPEDEF
The typedef is there for your convenience. Instead of having to work out a complex declaration, you can use typedefs to make the syntax simpler without changing the semantics.

Narue 5,707 Bad Cop Team Colleague

>given a function, how do you tell the size of the array that is passed?
Given a function where the only parameter is a pointer to the first element of said array, you don't. There's no portable method, which is why the usual advice is a second parameter with the size:

void myfunction(char * pointerToString, size_t size)
Narue 5,707 Bad Cop Team Colleague

If you have an actual array, you can use the sizeof trick regardless of the type of the array:

int Rows = sizeof arrString / sizeof *arrString;

This divides the size of the array in bytes by the size of the first element of the array in bytes. Since std::string uses dynamic memory for the string contents, the size of each string object will be consistent, just as if you used an array of pointers to char instead of arrays of char for the first example:

const char *arrChar[] = {
  "Anagram",
  "Book",
  "Computer",
  "Dimension",
  "Epic",
  "Fail",
  "Gyroscope",
  "Hemingway",
  "Irish"
};

int Rows = sizeof arrChar / sizeof *arrayChar;

The actual strings have different lengths, but the size of a pointer to char is constant, so the sizeof trick works.

Now, if you're passing the array to a function, this trick no longer works because inside the function the array is no longer an array; it's a pointer. The ideal solution is to pass the size of the array as a second argument. That's a great deal safer and more efficient than the leading alternative, which is to place a sentinel at the end of the array:

const char *arrChar[] = {
  "Anagram",
  "Book",
  "Computer",
  "Dimension",
  "Epic",
  "Fail",
  "Gyroscope",
  "Hemingway",
  "Irish",
  0 // Sentinel
};

int sentinel_size ( const char **array )
{
  int i;

  for ( i = 0; array[i] != 0; i++ )
    ;

  return i;
}
Narue 5,707 Bad Cop Team Colleague

>I am unable to understand How and where will such a pointer be useful?
I assume you mean a pointer to a function in general. One example is in the C standard library: qsort. Without using a pointer to a function as a callback, there wouldn't be a good way to make the function generic.

Narue 5,707 Bad Cop Team Colleague

[psychic debugging]
This describes your problem and shows ways to get around it without changing your input logic.
[/psychic debugging]

tux4life commented: What does "psychic debugging" mean? +4
Narue 5,707 Bad Cop Team Colleague

>it always reminds me that i am a foreigner and causes some sort of alienation.
But you are a foreigner. No amount of pretending otherwise will change that, and it's kind of insulting to your country of origin (not to mention your family). Also keep in mind that even if you change your name, you may still feel like a foreigner unless it's a distinctly American name (which Julian is not). For example, people ask me if I'm french on a regular basis when I introduce myself as Julienne.

Narue 5,707 Bad Cop Team Colleague

>-How did this type of work interest you and how did you get started?
I think I'm well suited to my job, and it interests me greatly. As for how I got started, I did it to win a bet.

>-How did you get your job? What jobs and experiences have led you to your present position?
I got my present job by being very good at what I do, and what I do is be awesome. :cool:

>-Can you suggest some ways a student could obtain this necessary experience?
Open source projects are a good way to get experience without having to convince someone to pay you. I've also found forums like Daniweb to be very instructive. You can solidify your own understanding and give back to the community at the same time.

>-What are the most important personal satisfactions and dissatisfactions connected with your occupation?
When I stop learning, I'll switch jobs. The most important "satisfaction" to me is learning new things.

>-Why did you decide to work for this company?
It didn't require me to relocate.

>-What do you like most about this company?
I get to do what I enjoy and what I'm good at. :)

>-Do you find your job boring or exciting? Why?
It depends on the day. Sometimes I'm having a hackergasm with new and interesting code, sometimes I'm writing documentation. You can guess which of those I find exciting. …

Sgt. Pepper commented: Thank You! +2
Narue 5,707 Bad Cop Team Colleague

>but it seems that this generator isn´t really random
Any deterministic method for generating random numbers won't be "really" random. That's why they're called pseudorandom numbers. They're sufficiently patternless to appear random for many purposes. "Real" random numbers only come from truly random real world sources, such as the decay of a radioactive material or atmospheric noise.

>because it seems to generate the same "Random"
>sequence chain every time I restart the application
That's a good thing. Imagine trying to debug your program when you can't reproduce the same sequence, ever. The seed for rand defaults to 1, and you can call srand to change it. Here's a demo of seeding based on the current time:

#include <climits>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>

namespace JSW {
    using namespace std;

    // Replaces the conventional but non-portable
    //    (unsigned)time(NULL)
    // as a seed for srand with a portable and
    // equivalent quality seed generator based 
    // on the current time
    unsigned time_seed()
    {
        time_t now = time ( 0 );
        unsigned char *p = (unsigned char *)&now;
        unsigned seed = 0;

        for ( size_t i = 0; i < sizeof now; i++ )
            seed = seed * ( UCHAR_MAX + 2U ) + p[i];

        return seed;
    }

    // Just for output formatting
    size_t digits ( int value )
    {
        if ( value == 0 )
            return 1;

        size_t n = 0;

        for ( n = 0; value != 0; n++ )
            value /= 10; …
Dave Sinkula commented: Props for repeating your seeding. +18
Narue 5,707 Bad Cop Team Colleague

>What is the difference between programming and scripting?
Scripting is generally thought of as application extension that cannot run without the aid of a hosting application. Shell scripts, for example, can't run without the aid of the shell, but they're not a component of the shell. Programming on the other hand is the development of independent applications that can run without any aid at all, or no more than the aid of the operating system. The shell itself is an example as it runs directly on top of the OS.

>What types of job positions are computer programmers needed
>for, Other than the obvious software development types?
Just about any job where you might be asked to customize a computer system.

Narue 5,707 Bad Cop Team Colleague

>Whatta load of bullshit.
Pure coincidence. I'm not so childish as to leave over a trivial thing like that. I so much more childish that I'd stick around to make everyone miserable. ;)

Narue 5,707 Bad Cop Team Colleague

>Really? I thought you pouted and left. :p
I didn't even know about that infraction for the longest time. Dani had to tell me about it before I noticed. ;)

Narue 5,707 Bad Cop Team Colleague

>Which makes me curious: Did you ever get an infraction
>for (for example) breaking the 'keep it pleasant' rule?
Yes, I have one Keep It Pleasant infraction (expired) on my account for this post.

>Who would give you such an infraction? The mods or the admins?
Regular members can be given an infraction by everyone (admins, super mods, and regular mods). Mods can be given an infraction by super mods and admins. Super mods can be given an infraction by admins, and admins presumably can infract each other. I won't say who gave me my infraction, but I wear it as a badge of honor. ;)

Narue 5,707 Bad Cop Team Colleague

>let us give him one more chance?
He'll get another chance: when he's automatically unbanned after the infractions expire.

>despite all odds he was a valuable poster.
>we need to take his age into consideration as well
There are no exceptions, no double standards. It doesn't matter if you're the new guy on the block, an oldtimer with thousands of posts and a massive reputation, or a moderator. If you break the rules, you suffer the same consequences as everybody else.

Narue 5,707 Bad Cop Team Colleague

>So the information was correct?
Pretty much.

>but is the C++ way of handling exceptions the preferred way to handle this ?
It depends. Unless you have a good reason though, you should prefer the default throwing behavior.

Narue 5,707 Bad Cop Team Colleague

>>>Is this the right way to do it?
>No.
No. When you use nothrow, new returns a null pointer instead of throwing bad_alloc.

Your catch is also malformed. ;)

Narue 5,707 Bad Cop Team Colleague

>it's probably because you aren't freeing the block
>of memory you're allocating in your call to malloc
No, it's probably not. Even if the process doesn't release allocated memory when it terminates, all you're likely to get is leaked memory, not a segmentation fault.

>memcpy(&pData, &t, sizeof(t));
>memcpy(&a, &pData, sizeof(t));
pData is already a pointer. Remove the address-of operator and watch it magically begin working:

memcpy(pData, &t, sizeof(t));
memcpy(&a, pData, sizeof(t));
Narue 5,707 Bad Cop Team Colleague

>How can i give the values programatically and not by user selection?
That's even easier. Just replace scanf with an assignment to nv of whatever expression you want:

nv = 5;

/* allocate memory for the adjacency memory */
adj_matrix = (int**)malloc(sizeof(int*) * nv);
Narue 5,707 Bad Cop Team Colleague

You had an assignment in your inner loop condition rather than a comparison. I also added the code to insert the new columns as it's an identical operation to inserting the new rows:

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<short>vec;
    vector< vector<short> >vec_2d;
    vector< vector<short> >vec_2d_padded;
    // Initialize a 2D C++ vector.
    for (int i=1; i<17; i++)
    {
        vec.push_back(i);
        if (i%4 == 0)
        {
            vec_2d.push_back(vec);
            vec.clear();
        }
    }

    // Expand by repeating the first and last row.
    vector< vector<short> >::iterator it;
    it = vec_2d.begin();
    vec_2d.insert(it,vec_2d.front());
    vec_2d.push_back(vec_2d.back());

    // Things seem to go bad here.
    for (it=vec_2d.begin(); it<vec_2d.end(); it++)
    {
        vector<short>::iterator it_1d;

        // Expand by repeating the first and last column
        it->insert ( it->begin(), it->front() );
        it->push_back ( it->back() );

        for (it_1d=(*it).begin(); it_1d != (*it).end(); it_1d++)
        {
            cout<<" "<<*it_1d;
        }

        cout<<'\n';
    }
    return 0;
}
Narue 5,707 Bad Cop Team Colleague

Each one designate a level of indirection (a pointer). So you can say that adj_matrix is a pointer to a pointer to int. My spidey sense says that adj_matrix is intended to be a dynamically allocated adjacency matrix, so you can do a google search for dynamic arrays in C++ for further details (or ask another specific question here).

Narue 5,707 Bad Cop Team Colleague

>are you understand me??
I are understand you just fine. :icon_rolleyes: You want me to give you code to add matrices, which isn't going to happen because you haven't given us any proof of effort yet. In fact, the only code in this thread was posted by me.

So is it that you don't understand how adding matrices works? Or are you just too lazy to turn it into code?

iamthwee commented: Excellent come back +19
Narue 5,707 Bad Cop Team Colleague

>i mean how to make two matrices
If you can make one, you can make two, or three, or umpteen. :icon_rolleyes:

Narue 5,707 Bad Cop Team Colleague

So what's the problem?

Narue 5,707 Bad Cop Team Colleague

If you want an alias, that's easy:

int *p = something;
int *q = p;

Now q is an alias for p; they both point to the same thing. However, note that if you change that thing, both p and q will reflect that change. You can reseat either p or q to point somewhere else and that won't affect the other.

I'm getting mixed signals. Perhaps you should explain exactly what you're trying to do rather than how you're trying to do it.

Narue 5,707 Bad Cop Team Colleague

>Why not just int *p = new int[M]; ?
Because then it wouldn't be a matrix? :icon_rolleyes: The usual interpretation of the term "matrix" is a rectangular array, or a two-dimensional vector. Or were you asking something completely different?

Narue 5,707 Bad Cop Team Colleague

What do you know about new[] and delete[]? If the size has to be variable then you're going to end up messing with dynamic memory, as I assume you can't use the std::vector class. Here's some code to get you started:

int **p = new int*[M];

for ( int i = 0; i < M; i++ )
  p[i] = new int[N];

// And to release the memory:
for ( int i = 0; i < M; i++ )
  delete[] p[i];

delete[] p;
Narue 5,707 Bad Cop Team Colleague

The error is saying that you declared the FlightManager constructor ( FlightManager(); ) but never defined it. You must give a body to any functions before you can call them.

Narue 5,707 Bad Cop Team Colleague

>can any of u explain the order of constructors
It's in the order of declaration, from base classes to derived classes. Take B1, B2, and V2. The diagram doesn't (and can't) specify whether B1 or B2 is called first because that would depend on the declaration order. This will print "B1, B2, V2" because B1 is declared before B2 in V2's definition:

#include <iostream>

class B1 {
public:
    B1() { std::cout<<"B1, "; }
};

class B2 {
public:
    B2() { std::cout<<"B2, "; }
};

class V2: public B1, public B2 {
public:
    V2() { std::cout<<"V2\n"; }
};

int main()
{
    V2 v;
}

But this will print "B2, B1, V2" because B1 and B2 are switched such that B2 is declared before B1 in V2's definition:

#include <iostream>

class B1 {
public:
    B1() { std::cout<<"B1, "; }
};

class B2 {
public:
    B2() { std::cout<<"B2, "; }
};

class V2: public B2, public B1 {
public:
    V2() { std::cout<<"V2\n"; }
};

int main()
{
    V2 v;
}
Narue 5,707 Bad Cop Team Colleague

>Since Generics were introduced, link lists are pretty much useless in the real world.
It's certainly true that you should prefer a standard library to hand-rolled code in most real world cases. However, just because there's a library that will do it for you doesn't mean you don't still need to learn how to do it manually. The understanding you acquire from implementing something is far more valuable than the thing itself.

Writing a linked list class teaches you the trade-offs that need to be made, which helps you understand the libraries better. If you've written a linked list, you're in a better position to know when to use one. And of course, if you suddenly find yourself unable to use the library for any reason, you're not caught out with your pecker flapping in the wind. You can just replace it.

>but can anyone see any reason why current.next in the
>examples above could not be replaced with current and visa versa?
Yep. In your addToBack method:

while (current.next != null)   
    current = current.next ;     

current.next = newElement ;

If the loop reaches nulll, the subsequent statement will throw a null exception. The intention of the loop is to end on the last valid node, then append to it.

In your removeLastElement method:

while (current.next != null) 
{
    previous = current ;  
    current = current.next ;          
}

Once again if the loop reaches null, it's too late. The intention of this …

Narue 5,707 Bad Cop Team Colleague

>it seems to be assigning it to the address of the pointer, not the value of the pointer
Yep, seeing as how that's what you told it to do. Unless you do some dereferencing, you can expect to be working only with addresses.

>so I'm wondering how to make it assign the pointer to the value
Let's get one thing straight. You can assign a value to an object, or an address to a pointer. No mixey matchy. If you want to assign the value pointed to by this to the object pointed to by rabbits, you would dereference them both:

*a = *b; // Copy the value pointed to by b to the object pointed to by a
Narue 5,707 Bad Cop Team Colleague

Narue, you're right but I provided him with this trick because his function was returning an integer value ...

And that makes a difference, how?

Narue 5,707 Bad Cop Team Colleague

>Will a-'0';
>be true for all the constants.in different character map sets?
Digits are required by the C++ standard to be contiguous, but if you need to convert to hexadecimal, you can't portably use that trick. Try an array instead, using the index as your value:

const char digits[] = "0123456789ABCDEF";
tux4life commented: Very good :) +3
Narue 5,707 Bad Cop Team Colleague

>I am getting a segmentation fault when i run the follwing program.
How does your code handle N^0?

>Code tags work sometimes and code tags donot work.
Define "do not work".

Sky Diploma commented: How do you catch those errors? :) +3
Narue 5,707 Bad Cop Team Colleague

Alright serkan sendur, that's quite enough. I've been ignoring your creepy and unhealthy fascination with me thusfar, but now you're getting dangerously close to harassment.

NicAx64 commented: really agree with you. look http://www.daniweb.com/forums/thread188808.html , they needs to destroy the C++ world.I personally respect you cos I learned many things by digging your threads and answers. I respect you and with you. +1
Nick Evan commented: And the ironic part is that he's a "featured poster". Haha :) +16
jbennet commented: he is VERY creepy +36
Narue 5,707 Bad Cop Team Colleague

Hmm, did you try actually setting the data member in your second constructor?

Narue 5,707 Bad Cop Team Colleague

>The guy taking over from my section asked that I give him an array for each word being input.
He probably just wants a C-style string then. You can use the c_str member function of the string class to get a C-style string. Though if I were you I'd ask the guy why he wants an "array". String objects are generally easier to work with, so it's possible he's just doing what he's comfortable with instead of looking for the best solution.

Narue 5,707 Bad Cop Team Colleague

>My problem is I would like to create a seperate array of characters for each element of that array.
To what end? There are ways to do what you want, but I'm not entirely sure what you want makes sense.

Narue 5,707 Bad Cop Team Colleague

>So to understand these codes detail what kind of books i have to read and tutorial i have to learn.
Why don't you just read the documentation on MSDN? It's all there.

>strcat(system,”\\virus.exe”);
*sigh*

Narue 5,707 Bad Cop Team Colleague

>no C++ expert ( not me ) state that java like language is SUCKS
Java sucks[1]. Of course, C++ sucks too.

[1] I'm called a C++ expert enough that I suppose I can disprove your statement.

stephen84s commented: grr ... thats my bread and butter you are talking about !!! -2
tux4life commented: Just ignore stephen :) +3
Narue 5,707 Bad Cop Team Colleague

>how about this :
It's a well known and controversial rant that is often quoted out of context. Here's the context if you missed it: Linus thinks C++ is a bad language choice for Git (and similar low level projects). Git is a version control system that's written with similar design views as a file system.

Many of the abstractions from C++ don't make sense for such a project and would only serve to complicate it without buying anything substantial. Linus' logic is sound even if he comes off as a prick in voicing it.

He might have a similar opinion for any project in C++, but Linus isn't a C++ programmer. In much the same way physicists would ignore my rants about how the large hadron collider is poorly designed, C++ programmers should respond to Linus with a similar attitude of "the layman has an uninformed opinion, how quaint".

Narue 5,707 Bad Cop Team Colleague

>c++ is a better way to attract Narue's attention, i am honored when i get posts from her.
That's sad. The really pathetic part is that you're probably serious. :icon_rolleyes:

William Hemsworth commented: Well that made me laugh ;D +8
~s.o.s~ commented: It's good that your profile or homepage doesn't contain your mailing address... ;-) +27
Comatose commented: Carry Mace! I mean the big hammer-like thing ;) +12
iamthwee commented: I'm sorry for posting a link to your picture, I thought it would discourage him. -4