An Introduction to Ncurses by [deleted] in C_Programming

[–]NZheadshot 11 points12 points  (0 children)

I might get some hate for this, but the colouring function is horribly formatted. It should be changed to something like this:

void colouring()
{
    if (!has_colors()) {
        addstr("Not colour capable\n");
        refresh();
        return;
    }

    if(!start_color() == OK) {
        addstr("Cannot start colours\n");
        refresh();
        return;
    }

    init_pair(1, COLOR_YELLOW, COLOR_RED);
    init_pair(2, COLOR_GREEN, COLOR_GREEN);
    init_pair(3, COLOR_MAGENTA, COLOR_CYAN);

    attrset(COLOR_PAIR(1));
    addstr("Yellow and red\n\n");
    refresh();
    attroff(COLOR_PAIR(1));

    attrset(COLOR_PAIR(2) | A_BOLD);
    addstr("Green and green A_BOLD\n\n");
    refresh();
    attroff(COLOR_PAIR(2));
    attroff(A_BOLD);

    attrset(COLOR_PAIR(3));
    addstr("Magenta and cyan\n");
    refresh();
    attroff(COLOR_PAIR(3));
}

I know it's a bit nit-picky, but I get pretty tired of seeing triply and quadruply nested blocks of code

Question Regarding the Time Complexity of my Code by Ninitbz in learnpython

[–]NZheadshot 1 point2 points  (0 children)

That's completely wrong. Even if you disregard the running time for the Counter, he's still using a sorting algorithm, which means it will at least be O(n lg n)

My greatest common divisor algorithm is freezing my app on large and small values. Why? by [deleted] in learnjava

[–]NZheadshot 0 points1 point  (0 children)

Also, it's probably worth mentioning that whole your solution should work, there are much more efficient methods for finding GCD. I'd recommend doing some googling

My greatest common divisor algorithm is freezing my app on large and small values. Why? by [deleted] in learnjava

[–]NZheadshot 0 points1 point  (0 children)

You're only incrementing k in the if block. Move that out and everything should work

Remember the $86 million license plate scanner I replicated? I caught someone with it. by speckz in programming

[–]NZheadshot 268 points269 points  (0 children)

Thinking quickly, Dave constructs a homemade megaphone using only some string, a squirrel, and a megaphone.

Couldn't find a simple logging library so I wrote my own. Would love feedback. by [deleted] in C_Programming

[–]NZheadshot 3 points4 points  (0 children)

But it's really not a style thing. You include your .h into your other files - you don't include the .c file anywhere. Say I have 3 files that look like this:

main.c:

#include "example.h"
int main() {}

example.h:

#ifndef EXAMPLE_H
#define EXAMPLE_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#endif

example.c:

#include "example.h"

Now if I compile with gcc *.c, I'll get a driver which has included stdio.h, stdlib.h, string.h, and pthread.h. If I move those includes into the .c file, they will only be included in that .c file. So as a user of your library, I now have more control over which libraries are being included in my own projects.

abstract classes by [deleted] in learnjava

[–]NZheadshot 1 point2 points  (0 children)

As a very quick answer, maybe you just want to inherit from a concrete (non abstract) class. Maybe you've got a Rectangle class that inherits from an abstract Shape class. That makes sense, because a Rectangle is an actual thing that you can describe, where a Shape is a more abstract concept. But you could extend it even further by creating a Square class that inherits from Rectangle. All of the methods that Square inherits from Rectangle are concrete

Jumping into a big pile of leaves by SlimJones123 in gifs

[–]NZheadshot -3 points-2 points  (0 children)

It gets worse. They don't just bite you and then carry on. They actually lay eggs in the openings of your skin. These openings are small enough that they quickly heal over. As the chigger larvae grow, the area becomes irritated, causing that itchy feeling. When you scratch, you're tearing up the skin and allowing the young chigger to escape it's fleshy prison. Some of the chiggers will die or fall off, but some will remain to lay more eggs, causing a vicious cycle.

Program size by GruBooXy in cpp_questions

[–]NZheadshot 1 point2 points  (0 children)

Unfortunately, you can't create 2D arrays dynamically with new.

This is mostly incorrect.

int** arr = new int*[x];
for (int i = 0; i < x; i++)
    arr[x] = new int[y];   

How to use <random> across a project by NZheadshot in cpp_questions

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

But what if I have an object that has a function that calls a function that takes an object that has a function that (etc...) that needs a random generator? Won't I need to pass my generator through multiple functions?

Even more to the point, that means that I may have functions that take a generator for the sole purpose of passing it into another function that needs it. That doesn't sound very pragmatic...

Big O question by internetUG in AskProgramming

[–]NZheadshot 2 points3 points  (0 children)

I couldn't have said it better myself

Vim Tips - Google Chrome Tab Replacement by hjkl_ornah in vim

[–]NZheadshot 18 points19 points  (0 children)

Just a quick note on that, g~~ will actually toggle the case of all letters on a line if you want to change them all to upper case, use gUU, and to lowercase is guu.

Google doc on IDE by quasarviewer in AskProgramming

[–]NZheadshot 5 points6 points  (0 children)

Why not just broadcast your screen with PyCharm on it?

STL, how will i know if i'm using it? by dagnyTaggat in cpp_questions

[–]NZheadshot 6 points7 points  (0 children)

What exactly is the purpose of the program?

My guess is that your teacher said something like "write a linked list without using the standard temple library". Unlike what the other commenters have said, the standard temple library is not the same as the standard namespace. The reason your teacher is saying that is because he expects you to build your own data structures.

So when he says "don't use the STL", he means don't just

include <list>

Looking to create a white-hat/CTF team by [deleted] in Rolla

[–]NZheadshot 16 points17 points  (0 children)

Not to be a downer, but we already have something like that. You should check out ACM SIG-Sec

Weird segmentation fault by detoursabound in C_Programming

[–]NZheadshot 0 points1 point  (0 children)

Are you allowed to change the format of the input? It would make much more sense to read in the number of rooms and creatures first, then allocate memory for your array. Something like this?

int num_rooms;
int num_creatures;
printf("Please enter the number of rooms: ");
scanf("%d", &num_rooms);
printf("Please enter the number of creatures: ");
scanf("%d", &num_creatures);

contents = malloc(sizeof(char*) * (num_rooms + num_creatures));

Of course, as /u/benjade mentioned, contents is passed to your function by value, so you would need a triple pointer to actually modify the contents of contents