Narue 5,707 Bad Cop Team Colleague

Can anyone tell me the Coding for:

[ATTACH]18596[/ATTACH]


Help me!!!

I'd be happy to give you complete code so you don't have to do any work at all!

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

#define f(x) ((x)>0?((x)*((x)+1)/2):0)
#define g(x) (((int)sqrt(8.0*(x)+1)-1)/2)

int main(int c, char **v)
{
    if (c>1)
        for (c=0;c<f(atoi(v[1]));c++)printf("%s%*s%d",c==f(g(c))?"\n":" ",c==f(g(c))?atoi(v[1])-g(c)-1:0,"",g(c)+1);
    return !putchar('\n');
}

There's no need to thank me, I'm here to help. :)

kvprajapati commented: Punishment.. LOL (: +11
Narue 5,707 Bad Cop Team Colleague

It depends on the type and scope of the variable. Can you be more specific?

vedro-compota commented: +++ +1
Narue 5,707 Bad Cop Team Colleague

char is a keyword, you can't use it for a variable name. And don't use magic numbers. If you must rely on ASCII (std::tolower exists for a reason), at least use character literals:

if (c >= 'A' && c <= 'Z')
    c += 'a' - 'A';
Narue 5,707 Bad Cop Team Colleague

Simply churn out code, or code effectively? I can go four hours or so before a break is needed to maintain quality, but if the code can suck ass an all day caffeine fueled code orgy isn't improbable. I refuse to not get my eight hours of sleep though, so multiple days are out of the question.

jonsca commented: "if the code can suck ass an all day caffeine fueled code orgy isn't improbable" I think this should be the first line of your (first?) novel +0
Narue 5,707 Bad Cop Team Colleague

Yes,actually DaniWeb not so active. I never get right answer whenever i posted thread about my problem in programming or any. Normally less replies; sometimes, 0 replies.
Seems not interesting my thread. I prefer whirlpool forum which is based in Aus.

While it's possible that you're so advanced nobody on Daniweb knows the answers to your questions, I'm inclined to believe that failure to get a good answer (or sometimes any answer at all) means you didn't ask a smart question.

Narue 5,707 Bad Cop Team Colleague

If you give a wrong answer, someone will likely correct you, which leads to you learning more on top of the original question being answered. I don't see a downside to this process.

Narue 5,707 Bad Cop Team Colleague

This may be helpful. I think the real problem here is you're not seeding rand properly and expecting the default seed to be different each time (which it's not).

Narue 5,707 Bad Cop Team Colleague

It's not uncommon to have a mental image of people online that is a complete mismatch with their real world appearance. I thought it would be interesting to see how different members of Daniweb are perceived by their peers.

Pick any members you find interesting and describe how you imagine them to look/act in real life.

Narue 5,707 Bad Cop Team Colleague

Just fill the buffer back up and use the resulting count. The previous contents will be overwritten:

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

int main(void)
{
    FILE *in = fopen("test.txt", "r");
    char buffer[10];
    size_t n;

    if (in == NULL) {
        perror(NULL);
        return EXIT_FAILURE;
    }

    while ((n = fread(buffer, 1, sizeof buffer, in)) > 0)
        fwrite(buffer, 1, n, stdout);

    fclose(in);

    return 0;
}
moroccanplaya commented: genius thats what all im going to say, shes my life saver +1
Narue 5,707 Bad Cop Team Colleague

>I do have a few questions if Narue wouldn't mind helping me.
Then it's fortunate that I'm still around five years after this thread ended previously.

>How do i get it to printout only the sentance and not the spaces.
Presumably you don't want the newline character that fgets stores and gets throws away. It's a simple matter, though not as convenient as gets:

if (fgets(s, sizeof s, stdin) != NULL) {
    char *newline = strchr(s, '\n');

    if (newline != NULL)
        *newline = '\0';
}

The idea is to search for a newline (there will only be one at the end, if any) and replace it with a string terminator.

>}while (error='t');
You accidentally used = for assignment instead of == for comparison.

Narue 5,707 Bad Cop Team Colleague

>Is there any drawbacks for using "this" pointer?
It's harder to read and more work to type?

>Is it a good practice to use "this" all the time and whenever possible?
When it comes to this particular usage, I think this should be avoided except to resolve an ambiguity. However, it's a style issue. If you want to add a redundant this-> to everything, feel free.

Narue 5,707 Bad Cop Team Colleague

*sigh*

Okay, here's a better example. Instead of trying to cram letters into a smaller array, I've used an array that covers the whole range of the char type and then filter the output. It should be easier to follow:

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

int main(void)
{
    char freq[CHAR_MAX] = {0};
    int ch;
    int i;

    while ((ch = getchar()) != '\n' && ch != EOF)
        ++freq[ch];

    for (i = 0; i < CHAR_MAX; i++) {
        /* Only print the letters that were found */
        if (freq[i] > 0 && isalpha(i))
            printf("%c: %d\n", i, freq[i]);
    }

    return 0;
}

The idea of a character frequency table is that the character itself is used as an index into an array, and the array contains a count of how many times that character was found. So if the letter 'A' is in your string three times, freq would have a value of 3.

vinitmittal2008 commented: Amazing!! +1
Narue 5,707 Bad Cop Team Colleague

Short answer: cout is interpreting the object as a bool due to the volatile qualifier. It's a quirk of overloading for the << operator.

Long answer: A volatile pointer can't be converted to a non-volatile pointer without an explicit cast, so neither the char* nor the void* overload can be used when the << operator is called. There's no volatile qualified overload, and the closest match is the bool overload, thus your array is interpreted as a boolean value rather than an address or a string.

You can fix it a number of ways, but an explicit cast is probably what you wanted:

std::cout<< (char*)str <<std::endl;

p.s. While your compiler may set uninitialized variables to 0 automatically, it's a very bad idea to rely on that behavior because it's not universal. So in your loop, int i; should be int i = 0; .

Narue 5,707 Bad Cop Team Colleague

>May i know what type of portability issue with ch-'A' ?
There's an implicit presumption that the letters or are consecutive. It's a very common failure amongst people who have only ever worked with ASCII or the lower seven bits of Unicode. The usual counter example is EBCDIC, where the latin alphabet characters are not adjacent.

For example, 'i' has a value of 137 in EBCDIC, but 'j' has a value of 145. Using the ch-'a' pattern, you would end up with incorrect values and probably an out of range access in the case where the result is used as an array index and the array size doesn't account for such a direct character set to index conversion when there's "dead space" in the character set.

Narue 5,707 Bad Cop Team Colleague

By the way, when I said to point out the changes in my code and speculate, I was giving you an assignment. Please complete the assignment and post your answers here if you have the spare time. This kind of exercise is very instructive, especially when you have someone knowledgeable who can correct any misunderstandings as they arise.

Narue 5,707 Bad Cop Team Colleague

Essentially, all the people who post without code tags would instead get frustrated and/or confused and simply not post at all.

It's this focus on quantity over quality that drives clueful people away from Daniweb and attracts the dregs of the geek community.

I am hesitant to follow in the footsteps of sites such as CProgramming, as that site has been around MUCH longer than DaniWeb, and hasn't seen anywhere at all close to the growth or traffic that we have. Perhaps this is one of the reasons why.

The code tag test is a relatively new addition to cprog, and hasn't affected activity at all. Further, the quality of first posts has increased drastically since that measure was introduced. You know how I feel about Daniweb, but I won't hesitate to say that cprog is a much better community in terms of quality. Daniweb used to be better, and has gone down the tubes in recent years such that now all you'll find on the first page are necros, cheaters, leeches, and morons.

Now, I'm not advocating code detection because I think it's less valuable with the high volume and variance in language options. My personal opinion is that addressing the source of the issue would be more effective than treating the symptoms.

People don't use code tags for one of two reasons: laziness or ignorance. A solid tutorial on code tags (Daniweb has a rather more robust and obscure system than most forums) that's easy …

Narue 5,707 Bad Cop Team Colleague

>This is weird, if not creepy.
More like creepy, if not outright disturbing. Even more so in Dani's case due to easy to find real world contact information. At least when crazy stalkers start breathing heavy around me, I'm less frightened because they're unlikely to show up at my doorstep.

Narue 5,707 Bad Cop Team Colleague

Yes, you can buy motherboards that have multiple CPU slots. How do you think we managed multiple cores before multi-core processors came out? ;)

cwarn23 commented: Excellent information and gr8 news for me! +6
Narue 5,707 Bad Cop Team Colleague

>Is this Program Correct? or is there more conditions to check..?
No and no, respectively. Your algorithm for the leap year condition is correct, but your code has a little to be desired.

>#include <conio.h>
This header is completely unnecessary for this program. I highly recommend you get out of the habit of including unnecessary non-portable libraries.

>void main(void)
main has returned int for about 60 years. It looks like this:

int main(void)
{
  /* Your code here */

  return 0;
}

Or if you're accepting command line parameters, this:

int main(int argc, char *argv[])
{
  /* Your code here */

  return 0;
}

Nothing else is acceptable if you're a beginner.

>clrscr();
I hate this for two reasons:

  1. clrscr is not a portable function, which means you've limited your code to the compiler that it was written with. Further, clrscr is unnecessary in this situation, so you've needlessly destroyed portability.
  2. Clearing the screen at the beginning of the program is either pointless or antisocial. If you're running the program from an IDE, the output window is owned by the IDE and nothing will precede your first explicit output anyway. If you're running from the command line, removing the entirety of output from previous programs will piss off damn near everyone who uses your program.

>printf("\n\n enter a year::");
While I'm sure it works fine on your compiler and system, output is only guaranteed to be displayed …

vinitmittal2008 commented: so helpful info :) +1
Narue 5,707 Bad Cop Team Colleague

>Thanks for the help, but I was doing it right
If you expected a reassignment of rootNode in AppendNode to change rootnode in main, you were doing it wrong.

>I did not think it was a coding error, looked more like compiler issue to me.
Only a fool blames the compiler first. Your code doesn't match your expectations. It's a misunderstanding of pointers, not a compiler issue.

>either way value of i and thus of *p and thus of **p is changing.
Yes! So you've got the basic concept down, now you need to apply it to pointers instead of integers. Instead of changing the value of i, change what p points to. I can guarantee that the only way you'll be able to manage it is by assigning to *pp. My second example illustrates what your code was doing with wrong(), and what your code should be doing with right().

hyperion commented: I am not really a fool, just caught with some oversight :D +4
Narue 5,707 Bad Cop Team Colleague

>How could a JFrame, an image file, a video file or a text file etc...
>be represented by only a bunch of 000000's and 1111111's?

0 and 1 are really just a convenient notation for the electrical pulses a binary computer uses to generate streams of data. Those pulses are interpreted by a chain of consumers which convert the bit stream back and forth between different representations.

How can something as complex as an image be represented by a stream of 0's and 1's? By combining them into an equally complex language suitable for consumption by a display driver which then determines which pixels on a monitor to light up. When you really think about the complexity of the whole system, it's a wonder that computers work at all.

>Is it good or bad to think this way for a first year student?
It's good to understand such low level things, but probably not until a solid base in more practical matters is built. Keep it on the back burner, but don't stress too much about pretending that some things work by "magic" until you're in a better position to learn how they really work.

islam-morad commented: Great post, Thanks +1
Narue 5,707 Bad Cop Team Colleague

>But even after AppendNode call, rootnode is NULL.
Yes, because any changes to rootnode within AppendNode will not persist back to main. In AppendNode, rootNode is a copy of the pointer, not a reference to it. I suspect you need more study on how pointers work between functions:

#include <stdio.h>

void foo(int *p, int **pp)
{
    printf("foo()\n\tp:   %p\n", (void*)&p);
    printf("\tpp:  %p\n", (void*)&pp);
    printf("\t*pp: %p\n", (void*)*pp);
}

int main()
{
    int i = 123;
    int *p = &i;
    int **pp = &p;

    printf("main()\n\tp:   %p\n", (void*)&p);
    printf("\tpp:  %p\n", (void*)&pp);
    printf("\t*pp: %p\n", (void*)*pp);
    foo(p, pp);

    return 0;
}

The way to pass a reference to an object in C is by passing a pointer to that object. Notice how the address of the pointer p in foo is different from the address of p in main. That's because foo's p is a copy of the pointer, a completely different object. If you change where p points to in foo, p in main doesn't change unless you pass a pointer to p (ie. pp), and modify the dereferenced object:

#include <stdio.h>

void wrong(int *p)
{
    p = NULL;
}

void right(int **p)
{
    *p = NULL;
}

int main()
{
    int i = 123;
    int *p = &i;
    
    printf("%snull\n", p == NULL ? "" : "NOT ");
    wrong(p);
    printf("%snull\n", p == NULL ? "" : "NOT ");
    right(&p);
    printf("%snull\n", p == NULL ? "" : "NOT ");

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

>are there any specific video tutorials for people like me ?
Doubtful, and I wouldn't trust them if I knew of any. As a system analyst, your recommendations will be made on a case by case basis and somewhat subjective based on your experience. Much like with programming there are guidelines, but more often than not you'll discard the guidelines to achieve better results.

In other words, for jobs like this where it's more art than science, you're not likely to find step by step instruction that's worth a damn.

>i heard a system analyst can easily become a DBA with 1 or 2 courses from oracle, is that true
A good system analyst should be sufficiently skilled to land at least an entry level DBA job. You're expected to have a broad range of skills, and enough depth in each of them to be competent.

kvprajapati commented: nice. +0
HELL DRAGON commented: thanks alot +0
Narue 5,707 Bad Cop Team Colleague

Are you high? What makes you think anyone but God can help you with a question like that?

Fbody commented: :confused: I agree! +4
Narue 5,707 Bad Cop Team Colleague

>i would like to know more about the book before i buy it.
FYI, TAOCP consists of several volumes, and it's concentrated awesome. If I could only keep one of my books (I have many), it would be TAOCP (probably volume 3).

>Reviews as to how the Math in it is
Intense, but if you're not a math head you can still get a lot out of the books.

Narue 5,707 Bad Cop Team Colleague

>It's standard, if not for beginners.
Which is the single most annoying problem with how C is taught. Pointers are an integral part of the language, and really very simple conceptually. It's my opinion that they should be introduced as early as possible.

>Three ampersand (star) programmers are generally mocked a bit, however.
Three is uncommon, but fine. Four or more might raise some eyebrows though. I've never used more than five in production code.

Narue 5,707 Bad Cop Team Colleague

Yes and no. It depends upon whom you ask, but a common distinction is that the software engineer is more involved in the design aspects than the programmer, who simply churns out code according to an already specified design (ie. a code monkey).

Narue 5,707 Bad Cop Team Colleague

>BST::~BST();
How is it non-recursive when you try to call the destructor recursively (not a good idea)? Personally, I'm a fan of unraveling the tree into a vine to simplify destruction. Then it just becomes a linked list destruction algorithm:

BST::~BST()
{
    BinNodePtr save;

    for (BinNodePtr it = myRoot; it != NULL; it = save) {
        if (it->left == NULL) {
            save = it->right;
            delete it;
        }
        else {
            // Rotate the left link into a right link
            save = it->left;
            it->left = save->right;
            save->right = it;
        }
    }
}
Narue 5,707 Bad Cop Team Colleague

>while((fscanf(ifile,"%s%d",m.ip,&m.num))!=EOF)
I'd start with the fact that when fscanf is called, m.ip is an uninitialized pointer.

On a side note, using EOF as the test against fscanf isn't wrong, but it's not completely right either. One test case where your condition fails is if the string reads successfully, but the integer fails. In that case fscanf will return the number of successful conversions. As such, it's best practice to test for the number of expected conversions:

while (fscanf(ifile,"%s%d", m.ip, &m.num) != 2)

This also covers the case where fscanf returns EOF, because EOF is guaranteed to be a negative quantity.

Narue 5,707 Bad Cop Team Colleague

>I observe that the output it gets done only when cin.get(...) is being executed dunno why.
Because cout is tied to cin. When you make an input request on cin, cout is automatically flushed.

>please tell me a way to empty(forcefully output) a buffer at will.
There are a number of ways, but the two most common are:

cout<<endl; // Print a newline and flush
cout<<flush; // Just flush
Narue 5,707 Bad Cop Team Colleague

For various reasons, strings don't work like you expect in C. It's really best to simply see strings as arrays with a special value at the end, and treat them accordingly. For comparison, the strcmp function in <string.h> is what you would typically use to compare two strings:

if (strcmp(x, "test") == 0)
  printf("Great...\n");
else
  printf("What's wrong?\n");

Of course, you could also do it yourself with a loop, but that's silly when the standard library does it for you.

Narue 5,707 Bad Cop Team Colleague

A loop invariant is an assertion that doesn't change between the beginning of the loop and each iteration. In your code, one such assertion is that for any a[x] where x < i, target does not exist. This invariant is true prior to executing the loop because x would be less than 0, which is outside of the bounds of the array. The invariant is true during execution of the loop because you 1) use found as a flag to break the loop when a == target, and 2) do not increment i if target is found. Finally, the invariant is true after the loop because of how the loop is terminated. Either i == n and target does not exist in the entire array, or a is equal to target and target does not exist prior to a (otherwise the loop would have terminated sooner).

int i = 0;
bool found = false;
// Invariant (TRUE): -1 is an invalid index
while (i < n && !found)
{
  // Invariant (TRUE): The loop breaks without incrementing i when target is found
  if (a[i] == target)
    found = true;
  else 
    i = i + 1;
}
// Invariant (TRUE): i == n OR a[i] == target

Pre and post-conditions are not necessarily invariants, but they can be.

timb89 commented: Great Help! +3
Narue 5,707 Bad Cop Team Colleague

You're essentially using a recursive algorithm without the recursion. Might I suggest this tutorial?

timb89 commented: Helpful and added link which aided in correct answer! +3
Narue 5,707 Bad Cop Team Colleague

>if you dont want to help then dont make such comments.
I'd love to help you. But I'm not going to waste my time on a lost cause. If you can prove that you're not a lost cause, you'll find me to be an excellent resource. However, posting your assignment without any kind of attempt or specific question strongly suggests that you're yet another lazy cheater (we get a lot of them around here) looking for a free ride.

>in future, you also might need some help in something and i hope at that time,
>if you get the same reply as you said now to me, you will remember me then..

I remember people like you every time I help myself or teach myself something new. Would it interest you to know that I taught myself C through trial and error? I didn't discover all of the wonderful resources on the web until long after I had overcome the difficulties you're experiencing now, so your "I'm just a beginner wah wah wah" defense is falling on deaf ears.

Narue 5,707 Bad Cop Team Colleague

I take it you've already exhausted the tutorials and documentation on the Boost site?

Narue 5,707 Bad Cop Team Colleague

Provided the items are separated by whitespace, you can use the simplest form of stringstream I/O to break it apart:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::stringstream split("v 0.200006 -0.093641 0.584690");
    std::string token;

    while (split>> token)
        std::cout<< token <<'\n';
}
Narue 5,707 Bad Cop Team Colleague

>I do this in my core header
Hopefully because you want to use NULL, but don't want all of the extra stuff in the headers where it's defined. That's really the only good excuse for defining your own NULL exactly the way the implementation would.

>Does the compiler or system typically do anything with position zero of the local process memory?
It's typically reserved for system level stuff. Oddly enough, catching null pointer dereferences is not uncommon. ;)

>If calloc() is used in a structure containing a pointer, doesn't the pointer automatically point to (void*)0 ?
Let's look at this from a low level perspective:

int **p = calloc(1, sizeof *p);

You know that calloc is logically nothing more than a paired call to malloc and then memset:

int **p = malloc(1 * sizeof *p);

memset(p, 0, 1 * sizeof *p);

And memset is pretty stupid in that all it does is copy the value into each byte:

int **p = malloc(1 * sizeof *p);
char *dst = (char*)p;

while (dst < (char*)p + (1 * sizeof *p))
    *dst++ = 0;

Now *p is set to all bits zero: 0x00000000. But what if the implementation uses 0xdeadbeef as the internal representation of a null pointer? The compiler can easily recognize that *p = 0 or *p = (void*)0 is assigning a null pointer constant and automatically convert that constant to the internal value of 0xdeadbeef before assignment, but it can't do that …

Narue 5,707 Bad Cop Team Colleague
Ancient Dragon commented: Nice tutorial -- thanks for posting that link :) +33
Narue 5,707 Bad Cop Team Colleague

>But what are man pages ....
You program on Linux and don't know how to consult the man pages? Open up a command prompt and type "man". :)

>What do you mean by implement...
I mean do it yourself. If the function doesn't exist, write it.

Narue 5,707 Bad Cop Team Colleague

>I'm getting a warning message while compiling.
Judging by your thread title, the warning is something along the lines of "gets is unsafe". The usual recommendation is to prefer fgets because it allows one to provide a limit to the buffer whereas gets will just happily read until a newline (walking right off the end of the buffer if necessary).

>You can force gcc to hide warnings by compiling with the -w flag.
Note that while it's possible to hide warnings, most of the time it's a supremely stupid idea. Warnings are there for a reason. They don't keep a program from compiling, but they do notify you of potential problems at runtime.

Narue 5,707 Bad Cop Team Colleague

>I had no idea you can use a (void*) as a cast.
void* is the generic pointer type. You're pretty much guaranteed to be able to convert a pointer to and from void* without any problems. There's no such guarantee for any other arbitrary combination of pointer types. Performing a safe typecast is your first step in troubleshooting the problem.

>Nor have I seen the wording 'transient pointer'.
It's not official terminology. In fact, I made it up on the spot. ;)

Narue 5,707 Bad Cop Team Colleague

>char str[31], ch;
Let's start with this common error. EOF is guaranteed to be a negative quantity, but char may be unsigned. getc returns int for a reason, and that reason is to guarantee that EOF is representable regardless of the signedness of vanilla char.

>while((ch = getc(fp)) != '\n')
Your loops are contradictory and ultimately infinite. The outer loop waits for EOF, but the inner loop (which is your actual reading loop) doesn't stop when it sees EOF.

creeps commented: THE answer +1
Narue 5,707 Bad Cop Team Colleague

>You have to check for denominator and if it is zero, then throw exception.
I wouldn't use an exception in this case. Perhaps an assertion, because the user's input should be checked and sanitized long before the division takes place. In which case division by zero would be a programmer error in gracefully handling bad input rather than a truly exceptional runtime situation.

Narue 5,707 Bad Cop Team Colleague

...

I can't even laugh at this, it's too sad. I wish you the best of luck, because that's all you have left.

Narue 5,707 Bad Cop Team Colleague

In other words, you don't know anything about C++ and just randomly pasted the contents of a tutorial into your text editor. What a surprise that it doesn't compile. :icon_rolleyes:

tux4life commented: Hehe, you hit the nail right on the head. :) +8
Narue 5,707 Bad Cop Team Colleague

>What is the use of writing an integer before d or any formal specifiers.
It gives you more control over the output than the defaults. You can override field width, padding, justification, precision, sign display, and whatnot. In this case, you're changing the field width. For example, if you're writing a fixed width report where a field has N columns assigned to it, you can say fprintf(out, "%*d", N, value); to print the value right justified with whitespace padding that fits the the fixed column[1]. This is as opposed to the alternative where you would need a solution like this:

size_t value_len = get_value_len(value);

/* Pad unused field area with whitespace */
for (i = 0; i < N - value_len; i++)
    putc(' ', out);

fprintf(out, "%d", value);

A more common example might be pretty printing a matrix of integers:

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

int main(void)
{
    int i, j;

    for (i = 0; i < 5; i++) {
        for (j = 0; j < 5; j++)
            printf("%4d", rand() % 100);
        puts("");
    }

    return 0;
}

Note that the last value on each row does not end with a space (which would happen if you used "%d " as the format string), and the columns are lined up nicely despite values of varying width.


[1] Of course, the default behavior is that if the value is larger than the field width, it's not truncated, so in the case of a fixed width report you …

Narue 5,707 Bad Cop Team Colleague

>but its has its own merits...
There are no merits to gets.

>say, the ease of accepting strings...
I've argued this point with authors before (Dan Gookin is one such example), and have yet to hear a sufficiently good explanation of how fgets(s, n, stdin) is so hard that it justifies the teaching of unsafe programming habits. Also, it's very common for programmers to prefer the first technique they learn for a task, and if the first thing they learn is gets...

Narue 5,707 Bad Cop Team Colleague

I want a publisher to let me write a book on C. But wanting something doesn't make it happen, especially when it involves other people doing work for you with no benefit to them.

Takeshi91k commented: Nice Post :D +0
Narue 5,707 Bad Cop Team Colleague

>Hmm... keeping the dictionary in an external file seems like the best approach to me. Correct me if I'm wrong.
How do you suggest looking up a word? Search the file each time? Unless it's a properly designed external database, that's going to be very inefficient. The words will likely all fit in memory, so an internal data structure makes more sense here.

>But to solve this problem he can have all the strings on one line.
Once again, looking up a word is tedious and potentially inefficient. You'd have to parse out the words every time, or store them in a separate data structure. But if you're using a separate data structure anyway, just use that as the primary storage medium.

>Use a linked list of words.
I'd use a balanced binary search tree or a chained hash table. Since this is a dictionary, we can expect lookup to be the primary operation. Searching a linked list of 50k+ words may not be the best approach. Of course, you can try amortizing the performance with tricks like moving the most recent match to the front, but I think a data structure better suited to searching is the superior option.

tux4life commented: Nice post :) +8
Narue 5,707 Bad Cop Team Colleague

>this is my first time programing and the class i am in uses savitch absolute c++
You don't need to defend yourself. We all had to start somewhere, and making mistakes comes with the territory.

>do you recommend supplementary materials for a beginner, because i am having difficulty with the text.
I haven't read that one. Could you elaborate on what parts you're having trouble with?

chococrack commented: always a delight +2