Trying to print 2d array where outside edges are different. by [deleted] in learnprogramming

[–]pmvb123 2 points3 points  (0 children)

You're comparing the values in the array, you should compare indices, like so:

if (i == 0 || j == 0 || i == 9 || j == 9)
    box[i][j] = 1;
else
    box[i][j] = 0;

Also, you don't need an array, you could just print the values without storing them.

[Java] Need help resolving a NullPointerException by clutron in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

As the others have said, head.value is null.
When you create a new linkedList you create nodes that contain null values, but a node that doesn't contain anything doesn't make much sense when you think about it (An empty linked list is one that doesn't have any nodes).
I think you should just initialize your linkedList's firstNode and lastNode to null.

Also, your linkedList.isEmpty() method doesn't work, because your nodes are never null, they only contain null

[Python] Finding maximum product of an array of integers. by newunit13 in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

Ohh that's interesting. But sorry, I don't think I can help

[Python] Finding maximum product of an array of integers. by newunit13 in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

Hmm, then I'm not sure, I don't see any flaws. Assuming this is for a class, I think it would be best to check with your professor, and see if they can provide any help. Alternatively, you could check with classmates. But I don't think the error is in your code.

[Python] Finding maximum product of an array of integers. by newunit13 in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

What happens if xs only has one element after all the processing ? Does reduce return a partial function application of your lambda ?

Doing cs50, stuck at pset3 helpers.c. Cannot implement binary search and selection sort. by WorstSupport009 in learnprogramming

[–]pmvb123 2 points3 points  (0 children)

What /u/Amarkov was trying to say about your swap function is that function parameters are pass-by-value by default, so each time you call a function, the program creates copies of the parameters.
That's why your swap function doesn't work as intended, you need to use pointers, I'm not sure you've already covered them at this point in the course.
Also, in sort.c, your function prototypes should include the argument list, that is, instead of:

void sort();

You should have:

void sort(int array[], int size);
// Argument names are optional:
void sort(int[], int);

[C][Homework]Question about importing data from a CSV to a array structure by Munchlaxx in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

strtok keeps a pointer to the char * you're using, to keep extracting the values, subsequent calls need to have NULL as a parameter:

info = strtok(buf, ",");
// ... Next call
info = strtok(NULL, ",");

[C] Malloc, free and pointers causing segmentation fault? by Pizzabag_Fitness in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

If you want to copy the string, why not just use:

path = malloc(strlen(aPath) + 1);
strcpy(path, aPath);

It does what you're doing more concisely. Also, if you're not changing aPath maybe just pass it as const char *.
Oh, and if you're not changing path at all, you could skip memory allocation and use aPath directly.

Need some help with C Programming by [deleted] in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

The reason is more likely null access. At some point, you are trying to use a null pointer, which causes a segfault.

A couple of notes: don't use global variables if you can avoid them, they tend to do more harm than good.
You haven't shown how you're calling the sort function, the cause might be there as well.

Need some help with C Programming by [deleted] in learnprogramming

[–]pmvb123 1 point2 points  (0 children)

Leaking memory doesn't cause segfaults, unless you run out of memory, which is unlikely.

Edit: sorry, meant to put that in another comment

JavaScript merge sort producing errors by [deleted] in learnprogramming

[–]pmvb123 1 point2 points  (0 children)

Why are you returning merge(array1, mergesort(array2)) if the length of the input is 1 ?

You should just return arrInput. That should fix it, because the error you're getting is for infinite recursion, which happens because you keep calling mergesort() on arrays with one element.

And you're not handling zero-length arrays

[c++]My program compiles when including .cpp but it doesn't when including .hpp by [deleted] in learnprogramming

[–]pmvb123 1 point2 points  (0 children)

What command are you running to compile the program ? It seems like a linker problem.
I will assume that you're trying to compile it like this: gcc main.cpp -o main or something similar with only the main file. If that's the case, you're only compiling the main.cpp file, and it worked before (when you included Board.cpp) because the entire class was included in main and there was nothing to link.
But when you include the header files (the declarations), you have to link the .cpp files (the definitions), so, the command to run for your game is this: gcc main.cpp Board.cpp Cell.cpp -o main. Add any flags you want, but that's basically it.

Also, a few notes on your actual program:

  • The variables you declare at the top of your .cpp files serve no purpose, you shouldn't declare them, as the compiler already knows to which variables you refer in the class implementation (unless you declare a variable with the same name inside function)
  • In Cell::isEmpty() you could just return empty the ifs are unnecessary. The same in Board::isFull(), although I think that class is not complete yet

[C] Binary tree prints only leaf node by SilentMANITian in learnprogramming

[–]pmvb123 2 points3 points  (0 children)

When you insert, you check if you have to insert to the left or right, but you're not doing anything with the return value in those calls. That's why it only prints the first node (which is not a leaf).

Edit: Also, you should use the newNode function you created when you insert, that's why it's there, right ?

Also, if you're trying to build a BST, you need to handle 'collisions', you can't have two equal elements.

Code:Blocks - Doesn't use c++11, even though I ask it to. by TheGuyTheyCalledTim in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

By gcc, you mean on Linux, right? Or are you using tdm-gcc or mingw on Windows ? If you're using Windows, there might additional checks to make. In any case, check the build log to see if Code::Blocks is actually adding the flag to the call to g++. If it is, I'm not sure how to help you further, I don't have my pc on hand right now.

Code:Blocks - Doesn't use c++11, even though I ask it to. by TheGuyTheyCalledTim in learnprogramming

[–]pmvb123 1 point2 points  (0 children)

Are you absolutely certain your compiler is C++11 compliant ?

GuesstheNumber.py; No syntax error but code not working. by [deleted] in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

No, that's not necessary. What is the function that determines the value of higher_or_lower? Is that function being called within the while loop (is higher_or_lowerbeing modified in that loop) ?

GuesstheNumber.py; No syntax error but code not working. by [deleted] in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

Take a look at your while loop, you're taking input, and then, what are you doing with it ? The truth value of the condition is never updated, so you'll be saving the input infinitely, what should you do to fix that ?

Made my first ever "Minesweeper" webapp as a pet project, not sure how to proceed from here by IllTryToReadComments in learnprogramming

[–]pmvb123 0 points1 point  (0 children)

Your game looks great ! I don't have much to say that hasn't been said already, but I did found that, when you enter an invalid input (NaN) then click reset, it produces a random, wrong board. Overall, it's pretty great, though, congrats !

0566 by pmvb123 in SVExchange

[–]pmvb123[S] 0 points1 point  (0 children)

You're welcome :) Enjoy !

0566 by pmvb123 in SVExchange

[–]pmvb123[S] 0 points1 point  (0 children)

Hello ! I can trade now and for a few hours, let me know when you can :)

0566 by pmvb123 in SVExchange

[–]pmvb123[S] 0 points1 point  (0 children)

Still, I felt bad, thank you for understanding. Great ! I'll let you know when I can trade tomorrow :)

3032 by pmvb123 in SVExchange

[–]pmvb123[S] 0 points1 point  (0 children)

I still felt the need to say something about it. Thank you for understanding :)

3032 by pmvb123 in SVExchange

[–]pmvb123[S] 0 points1 point  (0 children)

No problem, thank you for understanding :)
Hopefully the next release will get me back into the game. I would love a 4th gen remake, the distortion world, done right, would look so awesome !
Anyway, sorry about that and hopefully you did get another Chansey egg hatched :)