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

Let's start with one quick clarification, XML is a text format. So technically you can save XML to a .txt file. ;)

I just can t see xml being a advanced technology for data saving and transportation.

That's because it's not. XML isn't the most human readable format out there, and it's very verbose. The cost of formatting versus actual data is high enough that you could describe XML as a wasteful text format.

On the other hand, XML is well known, very well supported by libraries and utilities, and an integral part of the .NET framework (think configuration files).

they always lack to provide an EXAMPLE WITH SOMETHING ELSE

I'm not sure why you would expect them to, unless they're arguing in favor of another format. In my experience, delimiter separated formats are the most common alternative to XML, but they tend to be less flexible.

castajiz_2 commented: tnx. +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Good luck. Feel free to ask for help when you have a question other than nothing at all or "I don't know where to start". :rolleyes:

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have done something but got confused along the line.

Don't you think it would be better to post what you've done and then explain the confusion you have rather than just post your assignment and hope someone can read your mind?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

This is a quirk of the C++ object model. Since the member function isn't virtual, the compiler knows exactly what function to call and doesn't depend on the object instance being valid. Technically, all non-virtual member functions are shared under the hood (virtual member functions work through a lookup table stored in the object). When you say a->func(), the generated code looks more like this:

struct A
{
    int _dmember;
};

void __class_A_12345_func(A *self)
{
    cout << "Inside A!! " << endl;
    cout << self->_dmember;
}

...

int main()
{
    A *a = NULL;

    __class_A_12345_func(a);

    return 1;
}

Given a low level view of how things are set up, it's easy to see how a->func() will work just peachy when a is a null pointer. However, the problem is inside the function where you request the value of an instance data member, which invokes undefined behavior because a is a null pointer. I'd expect a crash at that point, but your compiler may generate code that supresses it for this case. Regardless, the code is broken because the function tries to access something that relies on a valid instance.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

That's either sweet or creepy.

What makes the difference for the OR clause? ;)

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I can make the insertion and deletion programs but not with these

Can you elaborate on what you mean by "but not with these"? The pseudocode is very specific and only needs to be translated to C++. The std::string class has member functions for finding the length, extracting a substring, and contatenation. I fail to see what the problem is.

Its not my homework

It's a beginner's exercise, and thus homework. The term "homework" as concerns our rules spans more than official assignments given to you by a teacher. It also includes exercises you take upon yourself for education purposes.

As such, you need to show proof of effort if you want help.

rubberman commented: Amen to that! +12
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

If you don't add any code to the event handler, simply resetting it in the control properties will delete the code as well. If you do add code (even if you delete it immediately), the best approach is to delete the handler manually and also reset it in the control properties.

If you want to go full manual, you can find where the handler is attached in your compiler generated code and remove that rather than do it from the designer.

castajiz_2 commented: TNX! +3
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Since you're posting to a C++ forum, I'm assuming you know at least rudimentary C++. So the good news is that when you need a program, you can write it.

The bad news is that we won't write it for you. That would be cheating at what is clearly homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

In your debugger, copy the contents of sqledit and run the query manually from your database. This makes it easier to spot check queries because it eliminates the obscuring of issues through VB.NET boilerplate.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Then make best effort at explaining what you don't understand, why you don't understand it, and where clarification will help you understand. Just posting your homework assignment looks like you want someone else to do it for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please show some proof of effort as per Daniweb rules. Thank you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

then why when I run program all I get is endless 0's ?

Simple math says that many of the cells will contain 0 since x, y, or z will be 0, and 0 times anything results in 0. However, there's a bug in the code:

for (int y = 0; y<dimy; dimz++)

Notice the increment step modifies dimz rather than y.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Headers provide declarations for the library objects and types you use. C++ requires a declaration to exist, and because it would be a pain (not to mention non-portable) to declare things manually, the headers are provided to make your life easier.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Pasting the contents of the header into your file would do it, assuming you use the same header that came with your compiler. But all in all, that would be silly since as Banfa said, that's what the headers are for.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Being the go-to guy is a good thing. Be careful not to close doors on yourself. You never know what might happen by saying "yes" to a request.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It looks a lot like you just assumed I haven't started my homework because I didn't post what I have done.

Yup. I can only work with the available information. I notice that you still haven't posted what you've done or asked any real question. Please do so or I'll close this thread in violation of Daniweb's homework policy.

I appreciate you for stating your opinion, but that wasn't exactly what I asked for.

You didn't ask for anything, you just posted your homework assignment. Assuming that you're asking for someone to do it for you is not unreasonable. Your followup comment and downvote only suffice as further evidence of this assumption as being correct.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

No. Do your own homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I have an idea, how about you do something first, then ask for help. Because it looks a lot like you're trying to cheat by having other people do your homework.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'm not sure what the other answers looked like, but division and modulo may not be the best way to print this stuff out, especially in C where prepending to a string is not trivial. It may be a good idea to look into actual bitwise math operations.

It's decent enough, provided you reverse the string before printing it. This of course brings into question whether you can afford the memory cost of storing the characters, but often that cost is negligible.

Another alternative, assuming the number of bits are relatively small, is recursion.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Is this a bad idea?

Can you be more specific?

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Please ask a smart question. Just posting your homework assignment is insufficient.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Sometimes the file is "word number" and other times it is just "word".

That's actually very consistent. All you need to do is look for two potential line cases, which is easy:

while (fgets(line, sizeof line, pFile) != NULL)
{
    int items = sscanf(line, "%s %d", nam, &val);

    if (items == 1)
    {
        // Just a word
    }
    else if (items == 2)
    {
        // Word and number
    }
    else
    {
        // Error (probably a blank line)
    }
}

Is there something I need to be worried about?

The return value of fscanf is the number of items extracted. EOF is only returned when end of file is reached without extracting any items. Especially when reading a file format line by line with fscanf, you should be careful to make sure that your extraction doesn't accidentally span lines. Using EOF as the loop condition increases the risk of that happening. For strict formats, I strongly recommend checking for the number of extraction specifiers in your format string. For example, if you're extracting two items, test the result for 2:

while (fscanf(pFile, "%s %d", nam, &val) == 2)
{
    ...
}

If you can't follow that pattern, fscanf's return value shouldn't be used for the outer loop condition because making it work can get kind of hairy.

You'll notice that in my example I used fgets to read a single line, then sscanf to parse it. Further, I carefully checked the return value. …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'd create a class or structure for a course, then a class for a student that has a vector (or array if you so choose) of courses. Finally, I'd create a vector (or array if you so choose) of students and be good to go.

class Course
{
    ...
};

class Student
{
    Course _courses[5]; // Since you asked for arrays
    ...
};

Student students[10]; // Since you asked for arrays
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What's the value of x? Neither of the values in notename suggest a valid file name, and if they do, you'd need to verify that the file is in the current working folder. I'd suggest trying perror to get more information on why the file didn't open successfully:

if (!readnote)
{
    perror("Read Error");
}

You can find perror in stdio.h.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Possible, yes. However, for clarity sake, I'd recommend following up your call to fscanf with fgetc and check the result for the character you want:

while (fscanf(pFile, "%99s", nam) == 1)
{
    int next = fgetc(pFile);

    if (next == ' ')
    {
        // Do something
    }
    else if (next == '\n')
    {
        // Do something
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

As long as they do not begin with numbers. Is this standard functionality?

Yes.

but then it is rather vague about what identifiers are, exactly.

You might be reading the wrong section. Section 2.11 (C++ n3242) gives both a grammar and a detailed description of syntax. Section 6.4.2 (C99) is equally detailed.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What does the server do? If all your clients need is database access then hitting a database on another machine is simple. If clients connect to a server that handles the heavy lifting, you'd need to look into something like WCF to manage the communication between them.

Another thing to consider is whether clients will be on the same network or across networks (such as across the internet) as that will affect your options in communication protocol.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

And if not, it would be good idea to have it, there are some constants that people use very often, so you cold try to writte them and then use them if you in need of it.

That's the approach I'd recommend. Create your own header with these things and reference it where needed. That way you don't depend on implementation-defined extensions.

but most do have limits.h

Everyone has that header, what I mean is that some variation of PI isn't a standard macro.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Actually, it's dead easy. Against my better judgment, since you haven't posted any code of your own, I'll give you a more complete sample.

#include <conio.h>
#include <iostream>
#include <string>
#include <vector>
#include <windows.h> 

using namespace std;

#define FOREGROUND_DEFAULT FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
#define BACKGROUND_DEFAULT 0
#define BACKGROUND_HIGHLIGHT BACKGROUND_BLUE | BACKGROUND_INTENSITY

/* System dependent key codes */
enum
{
    KEY_ESC     = 27,
    ARROW_UP    = 256 + 72,
    ARROW_DOWN  = 256 + 80,
    ARROW_LEFT  = 256 + 75,
    ARROW_RIGHT = 256 + 77
};

static int get_code()
{
    int ch = getch();

    if (ch == 0 || ch == 224)
    {
        ch = 256 + getch();
    }

    return ch;
}

void gotoxy(int x, int y)
{
    COORD coord = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}

void show_option(const string& option, bool highlighted)
{
    if (highlighted)
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_DEFAULT | BACKGROUND_HIGHLIGHT);
    }
    else
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_DEFAULT | BACKGROUND_DEFAULT);
    }

    cout << option << '\n';
}

int main()
{
    vector<string> options;
    int ch, pos = 0;

    options.push_back("1) Option 1");
    options.push_back("2) Option 2");
    options.push_back("3) Option 3");
    options.push_back("4) Option 4");

    for (int i = 0; i < options.size(); i++)
    {
        show_option(options[i], i == pos);
    }

    gotoxy(pos, 0);

    while ((ch = get_code() ) != KEY_ESC)
    {
        switch (ch) {
        case ARROW_UP:
            if (pos > 0)
            {
                show_option(options[pos], false);
                gotoxy(0, --pos);
                show_option(options[pos], true);
                gotoxy(0, pos);
            }

            break;
        case ARROW_DOWN:
            if (pos < options.size() - 1)
            {
                show_option(options[pos], false);
                gotoxy(0, ++pos);
                show_option(options[pos], true);
                gotoxy(0, pos);
            }

            break;
        }
    }

    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_DEFAULT | BACKGROUND_DEFAULT);
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

but thats not what i want

I'm aware of that. It's only a part of what you want, the part that recognizes arrow keys. You also need to move the cursor with something like gotoxy. My apologies, I thought it was obvious that I wasn't giving you a complete solution.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Here is something I wrote up years ago, but it should still be relevant to your needs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I am a programmer. That's why I'm receiving a paycheck. I sit alone in a small cubicle and do my work.

That's an interesting description of a programmer. I wish I could sit alone in my office and do my work without having to communicate with the rest of my team or end users, but that's not realistic. ;)

So my boss says to me today that I am being signed up for a FIVE day course in..... Microsoft OUTLOOK.

Unless the training involves teaching a component that you wrote, I'd agree that it's outside the scope of your job description as stated. That's not to say that your boss doesn't have a different idea of what your job description is, so the first step would be to get clarification and work from there.

If you're a programmer like me, what would you do?

I'd probably do it for the experience and to help out the users, but make it clear to my boss that this is outside the scope of my job description. I might also try to negotiate a bonus of some sort and have my boss handle scheduling and schmoozing of lost time for the days I wouldn't be doing the job I was hired for.

The last thing you want is to be punished for doing what was asked of you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Try to see it in limits.h

It might be there, but if it is, it's a library extension unique to your compiler.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

because the MSDN program still uses errror.h, and hendels the error in old fasion way!

You mean errno.h? _stat and FindFirstFile are both C-based API functions, so errno and return codes are essentially the only option for handling errors. You can wrap your own exception handling mechanism around it if you really want to, but the "old" way doesn't mean that it's not functional or effective. ;)

#include <errno.h>
#include <exception>
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>

using namespace std;

class StatException : public exception
{
    string _message;
    string _filename;
public:
    StatException(const string& message, const string& filename)
        : _message(message), _filename(filename)
    {}

    const char *what() const { return _message.c_str(); }
};

class FileStat
{
    struct _stat _buf;
public:
    FileStat(const string& filename)
    {
        if (_stat(filename.c_str(), &_buf))
        {
            switch (errno)
            {
            case ENOENT: throw StatException("File not found", filename);
            case EINVAL: throw StatException("Invalid parameter", filename);
            }
        }
    }

    _off_t Size() const { return _buf.st_size; }
};

int main()
{
    try
    {
        FileStat stat("test.txt");

        cout << "Size: " << stat.Size() << " bytes\n";
    }
    catch (const StatException& ex)
    {
        cerr << ex.what() << '\n';
    }
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I said that already :-P

I had my post composed and got distracted. You had replied by the time I clicked Submit.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The assignment uses a lot of words for not a lot of work. That's a good thing, because it's very detailed, and all you need to do is put it in UML/code form.

So now for the obligatory "what have you done"? It's against Daniweb rules to post just a homework assignment with the expectation that someone will do it for you.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The trick with this program is defining what's meant by a "word". You can't just take whatever is separated by whitespace and call it good, because that will incorrectly include punctuation.

To properly do it would require some lookahead and lookbehind, and even then poorly formatted sentences could cause an issue. So to a certain extent the program would need to be tailored to the expected input rather than act as a universal sentence recognizer.

Once you have reasonable tokenization logic, it's straightforward to do the deed:

#include <ctype.h>
#include <stdio.h>

int is_word_char(char c)
{
    return isalnum(c) || c == '\'' || c == '-';
}

const char *next_word(const char *s, size_t *len)
{
    *len = 0;

    // Find the next word
    while (*s != '\0' && !is_word_char(*s))
    {
        ++s;
    }

    // Find the end of the word
    while (s[*len] != '\0' && is_word_char(s[*len]))
    {
        ++(*len);
    }

    return *s != '\0' ? s : NULL;
}

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

    printf("Enter a sentence: ");
    fflush(stdout);

    if (fgets(line, sizeof line, stdin) != NULL)
    {
        const char *p = line, *longest_word;
        size_t len, longest_len = 0;

        while ((p = next_word(p, &len)) != NULL)
        {
            if (len > longest_len)
            {
                longest_word = p;
                longest_len = len;
            }

            p += len;
        }

        printf("Longest word: %.*s\n", longest_len, longest_word);
    }

    return 0;
}
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The date-time stamp on a post gives you a hard link to it that can then be pasted into another post.

For example

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Contact the ISO standards committee and submit a request to have your function added. Since that's not likely to happen, you'd be better off creating your own library that gets distributed with your program. ;)

Can you provide more details on this function and how it will be used? I can offer advice on the best approach.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

Why are you using getc? Does it play nicer with numbers than fgetc?

They do exactly the same thing. The only difference is that getc may be implemented as a macro, which in most cases makes no functional difference. Generally it only matters if the argument has side effects or you're trying to store a pointer to a function. In those two cases, fgetc should be used instead.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

English, please.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

It's nice only if you also like driving a Model-T automobile made 100 years ago.

Orwell is the current and maintained build of Dev-C++. If we were talking about the Bloodshed build I'd agree with you, but for those who like the Dev-C++ IDE, Orwell is a decent modern choice that won't hold you back.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I tested your code, and as it turns out "%1023[^\t\n]" is no different than "%1023s" because with %s scanf() stops converting when it encounters the first white space (space, tab, newline, and backspace).

Not quite, as your test results clearly show. ;) %s stops on all whitespace, which includes more than just tab and newline. Granted that those two will be the most common by far, but in general it's not safe to assume the file won't contain other whitespace sequences.

In either event it still doesn't work right because offset is only being incremented by 1 which produces undesireable results. offset has to be incremented to the beginning of the next field.

If the format is tab delimited, trimming non-tab whitespace from a field is the wrong behavior. It's another matter entirely if you need to support empty fields (ie. multiple adjacent delimiters). In that case a more intelligent parsing method would be required; scanf isn't well suited to complex delimited formats.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

A control can be a container for other controls, so such an algorithm should be recursive:

Private Sub SetControls(ByVal Control As parentCtrl)
    If TypeOf parentCtrl Is Label Then
        ' Set the label properties you want
    End If

    For Each ctrl As Control In parentCtrl.Controls
        SetControls(ctrl)
    Next
End Sub
deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I wouldn't recommend using %s unless you can guarantee that the fields won't contain embedded whitespace. Further, you should always use a field width for string specifiers in scanf to avoid buffer overflow.

Ignoring the possibility of quoted fields that contain embedded tabs, it's straightforward to read a line with fgets and then parse it with sscanf:

#include <stdio.h>

int main(void)
{
    FILE *in = fopen("input.txt", "r");

    if (in != NULL)
    {
        char line[1024];

        while (fgets(line, sizeof line, in) != NULL)
        {
            char field[1024];
            int offset = 0;

            // Break down the line based on tabs ('\n' included because fgets retains a newline if it's present)
            while (sscanf(line + offset, "%1023[^\t\n]", field) == 1)
            {
                puts(field);

                offset += strlen(field);

                // Safety check to avoid stepping off the end of the array
                if (line[offset] != '\0')
                {
                    ++offset;
                }
            }
        }

        fclose(in);
    }

    return 0;
}

Note the use of a scanset in scanf to look explicitly for tabs.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

You need to build up the number as digits are read, but not if non-digits are read. The trick is handling input so that you don't miss anything such as a number at the end of the file, which means not using a comparison against EOF as the loop condition:

#include <stdbool.h>
#include <ctype.h>
#include <stdio.h>

int main(void)
{
    FILE *in = fopen("input.txt", "r");

    if (in != NULL)
    {
        bool in_number = false;
        long long num = 0;

        while (true)
        {
            int ch = getc(in);

            if (!isdigit(ch))
            {
                if (in_number)
                {
                    printf("%lld\n", num);

                    // Reset for the next number
                    in_number = false;
                    num = 0;
                }
                else if (ch != EOF)
                {
                    printf("%c\n", ch);
                }

                if (ch == EOF)
                {
                    break;
                }
            }
            else
            {
                num = 10 * num + (ch - '0');
                in_number = true;
            }
        }

        fclose(in);
    }

    return 0;
}

However, there's still a problem. If you truly want to store the number as an integral value, you have to consider cases where the value will overflow. I chose to use a long long to limit the chance of that, but it still exists in an arbitrary file.

Doing an overflow check manually is harder that it might seem, especially when using the largest possible integer data type. A safer approach might be to store the number as a dynamic string and then use something like strtoll to do the conversion and error checking for you. I'll leave that as an exercise for you …

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

I'll also link you directly to here. A hashmap by definition is almost surely implemented using a hash table, but mapping data structures also commonly use balanced binary search trees (red black being the most popular for this purpose).

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

The debugger is called gdb. A quick Google search for "gdb tutorial" will get you started.

deceptikon 1,790 Code Sniper Team Colleague Featured Poster

What is the purpose of death? Is it an evolutionary trait? If so, why?

Our bodies wear out eventually such that old cells can no longer be replaced with new cells quickly enough to maintain life. It would be interesting to cross reference life span relative to habitat and complexity of physiology.

Life tries to live. It tries to stay alive. Breeding helps keep the species alive, but for what purpose? Why does life try to beget life when all it does is die? Seems pretty pointless if you ask me... (Not trying to be depressive here)

You said it yourself, life tries to live. Our basest instincts are to survive and procreate. As a debatably intelligent species, we tack on whatever makes us feel better about our seemingly miraculous existence. However, I'm not of the opinion that there's a satisfying answer to "what is the meaning of life?".

So, what if life as a whole is simply trying to exist?

I think a good question is why would that be a bad thing? Just because there's likely not a higher purpose in life doesn't mean we can't still live the way we want to the fullest.

On another level, things get really freaky when you consider looking at whether or not it was possible to have not existed.

That makes me think of universal predictability. Sure, my father could have pulled out or waited another second and I'd probably not be …