Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22248

setTitle() function is making crash my program if not hardcoded String

$
0
0

Since now I'm programming on my Maze game for College. I am almost ready. Just need to beautify it.

Here I thought 'bout making a setTitle function. Whenever testing it, it had some strange symptomps I've never seen.

So if I hardcode the title[255] array, title will be appended onto the cmd array. When setting the title as parameter in the function, and I give the value over to setTitle(char title[255]) (e.g. "* MAZE RUNNER*"), the program crashes.

I've tried different array sizes, but this symptom seems to appear randomly.

Maybe a beginner fault at my side?

void setTitle(char title[255]) {
    char cmd[] = "title ";
    strcat(cmd, title);
    system(cmd);
}

int main() {
    setTitle("Hello Stackoverflow! I hope you can help me! feelssadman:(");
    return 0;
}


Viewing all articles
Browse latest Browse all 22248

Trending Articles