Posts by Cooper • 117 points
4 posts
-
2
votes2
answers120
viewsQ: How to format strings and store them in a dynamic vector
In several parts of my code I need to use bash commands to run programs on Ubuntu. To do this, format the command using sprintf and then run with the system function. Ex: sprintf(sprintfoutput,…
-
2
votes1
answer263
viewsQ: How do I pass the first char address of a string to a function to write to it?
The problem is this: I made a function that takes the output of a given OS command and stores it in a string. The idea now would be to declare a single char string in my main function using malloc,…
-
4
votes2
answers267
viewsQ: Behaviour of malloc(1) in C
If I use char *char_commandout = (char *) malloc(1);, the allocated byte will store the " 0" at position 0 of the vector or will allocate a space for the value I want to store (at position 0) and…
-
2
votes2
answers303
viewsQ: Giving "Segmentation fault" when I try to open C files
The following code gives me "Segmentation fault (core dumped)" when trying to open the file after declaration and filling a string with sprintf. //Sem as duas seguintes linhas, o código roda…