nucleon 114 Posting Pro in Training

I don't feel like arguing. Can someone else weigh in on this? DFS or BFS?

nucleon 114 Posting Pro in Training

ajhais,
It should actually be a Breadth First Search (BFS), not a DFS.

nucleon 114 Posting Pro in Training

>>BTW, your solution does not work for a string of only spaces.
>Does for me.
Try this: int main() { printf ("%d\n", wordCount (" ")); } Should be 0; your code gives 1. Easy to fix, though.

>the poster seems to be tackling this the hard way
That's true.

nucleon 114 Posting Pro in Training

new returns a newly allocated address pointing to enough memory to hold a name structure.

BTW, your use of the word "member" threw me off at first because the members are string, next, and value, which don't enter into your question.

nucleon 114 Posting Pro in Training

I really don't see why this has to be so hard.

No one said it was particularly difficult; we were just trying to help without posting the answer. BTW, your solution does not work for a string of only spaces.

nucleon 114 Posting Pro in Training

There should be an option to not create a console window for a "console" program. There is in Dev-C++ (with gcc).

nucleon 114 Posting Pro in Training

csurfer makes an important point about testing only up to the square root of num. It will actually reduce the number of comparisons to much less than half. For example, with the number 101 you only need to test up to the number 10 -- quite a savings!

To reduce that number of comparisons by half again, you can test 2 separately and then only test odd numbers (stepping by 2 in the for loop), something like this:

sqr = (int) sqrt (num);
if (num % 2 == 0)
    isPrime = 0;
else
    for (i = 3; i < sqr; i += 2)
    ...
nucleon 114 Posting Pro in Training

What if there are two or more spaces between two words?
So you should skip any initial and final spaces, and count any intermediate spaces as one even if there are more than one.
And then add one (as long as you found at least one non-space on the line, otherwise there are zero words).

nucleon 114 Posting Pro in Training

Sorry csurfer, I wasn't thinking.

nucleon 114 Posting Pro in Training

Assuming you are invoking the compiler from the command line, try using the -s option.

nucleon 114 Posting Pro in Training

csurfer: Do you always just repeat what other people have already said?

nucleon 114 Posting Pro in Training

It seems that no one (so far) has come up with a simple solution. If you really want this, you can write your own "gotoxy", "cprintf", "textattr", etc., but have them work in GUI mode. Then you can pick whatever font size you wish. This would not be very difficult, but you have to know Windows programming, which can be somewhat difficult to learn.

nucleon 114 Posting Pro in Training

What compiler / OS ?

nucleon 114 Posting Pro in Training

You can replace your entire switch statement with table[lattice[i][j]][1]++ .

By the way, you are using ++ and -- incorrectly. It is NOT a = a++ , but simply a++ .

As for the segfault, it may be because of the way you are using rand(). Try changing everywhere it says rand() / (RAND_MAX / max) to rand() % max .

nucleon 114 Posting Pro in Training

What operating system are you running this on?

nucleon 114 Posting Pro in Training

That's not Aia's code, and it seems to be incorrect. Here's a working example. It lacks proper error checking for strtol, though. See the link in Aia's post above for the scoop on strtol.

int main (void)
{
    char *number = "1234.56";
    char *decimal;
    long int fraction = 0;

    if ((decimal = strchr (number, '.')) != NULL)
        fraction = strtol (decimal + 1, NULL, 10);

    printf ("%ld", fraction);
}
nucleon 114 Posting Pro in Training

It's been printing the number correctly all along. Since there are 33 zeroes after the decimal point before the 626 part, you get (approximately) zero! Use "%e" to print the number in exponential notation, or "%g" to print it in whichever is more compact. As for "%lf" it is best not to use it, since it is equivalent to "%f" in printf (but not in scanf).

nucleon 114 Posting Pro in Training

Narue: "Posers should know their limits."
You say it's rude to resurrect old threads but you're rude whenever you feel like it. One of the rules of this forum is "keep it pleasant". You are not following that rule. It's sad how a relatively simple skill like programming can go to a simpleton's head. Don't bother to respond; I won't read it.

Prabakar commented: I will say Nature is extremly kind to answer some stupid debates and was not rude in that post. Inspite of those harsh words by the prevoius poster Nature replied politely. +0
nucleon 114 Posting Pro in Training

Programmers do not use "word wrap".
Try hitting "Enter" once in a while.

nucleon 114 Posting Pro in Training

This seems to work just fine:

#include <stdlib.h>

int main()
{
    system("move \"folder 1\\test.txt\" \"c:\\test.txt\"");
}
nucleon 114 Posting Pro in Training

The OP was clearly trolling.

nucleon 114 Posting Pro in Training

Try scanf("%d", &(p->count));

nucleon 114 Posting Pro in Training

It's unclear what you wish to do.

Do you expect the user to enter a single character? If so there is nothing to count (it's ONE character).

So I'll assume you expect the user to enter more than one character and you are trying to count how many of each type of character (upper, lower, digit) the user entered.

In that case you should read the input into a string and loop over the chars in the string. You will need separate counters for each type.

nucleon 114 Posting Pro in Training

In num=((int)ceil(((double)rand()/RAND_MAX)*(max+1)))%(max+1); You are dividing and modding at the same time.
You need to choose one or the other.
With division (and floats): num = (int)(((double)rand() / (RAND_MAX + 1)) * max); or with modding (and ints) num = rand() % max; These both give between 0 (incl.) and max (excl.).
If you want 1 to max (both incl.), add + 1 to the very end of either.

nucleon 114 Posting Pro in Training

Or do it in one step:

For each char in str:
      If it's a space:
         * Remember that you saw a space, but don't
            copy it to the output string.
      Else (if it's not a space):
         * If it's not leading space:
            * Copy a space to the output string if
               any spaces were seen.
         * Copy the non-space char to the output string.
   Terminate output string.

Note that leading and trailing spaces are removed completely (not replaced with a single space).

nucleon 114 Posting Pro in Training

You have maze_in.get(ch) >> maze1[i][j]; It should be more like maze_in.get(ch); maze1[i][j] = ch; or maze_in.get(maze1[i][j]); Also, maze1 may be better as type char instead of string.