rastignac

joined 1 year ago
 

As much as neovim seems nice, I can't seem to find many resources to actually help start configuring neovim as a beginner. Help is very sparse, and the easiest thing seems to get a premade config, but then there are just too many features, and complexity gets in the way of understanding what's going on

 

I'll explain myself. I'm doing a small project using a few dependencies, so I have to add them when I call gcc. Everything else is really easy. I just have c files and header files. I find it really cumbersome to have to tell make what headers go with what c files when they have the same name. I don't see why we don't have a build system where you simply have to give a project folder with the name of source file with the main() function, give the name of the output executable, the external dependecies to be called with gcc, and that's it. Everything else can be automatically detected and linked apropriately, even with multiple folders inside the project folder. Does something like that exist that's simple to use, or is this doable in make?

[–] [email protected] 1 points 1 year ago

Thank you for your answer :)

 

I just started to get into neovim today, and I decided to follow the first tutorial I came across (neovim from scratch) on youtube. The first thing that's done is to copy the repo into .config/nvim/. At startup nvim set up a bunch of stuff. is there anything that it sets up outside of the ./config/nvim file? Because I really dislike installing stuff on my computer that just stays even after deleting the installation folder.

 

Hello,

I've installed the library called Raylib (https://www.raylib.com/). I followed the instructions to install the dynamic library. However, when compiling using gcc, including the raylib.h header dynamically in the source code produces an undefined reference error for every function I use from that library. That means that the library functions weren't attached to the executable at runtime, so gcc didn't find the right .so file.

To actually produce an executable, I have to use a shell script, that for some reason needs raylib's source code path. But that goes against the point of installing a dynamic library, since the latter is used so that source code can be compiled without library functions, instead putting them somewhere else to be shared with other executables.

Can someone explain to me how gcc finds the .so files and if anyone has used raylib dou you understand what the shell script does?

5
submitted 1 year ago* (last edited 1 year ago) by [email protected] to c/[email protected]
 

Hi guys, I'm writing a program using the pbm "P1" format to create a random bitmap. The '1' char represents a black pixel and the '0' char represents a white pixel. All that has to be done to use this format is to basically "draw" the image in a file using this system. I just want to make a char matrix and randomly put black pixels until I hit a maximum percentage of black pixels which I don't want to exceed. Then I print that matrix to a file.

What I don't understand is that even if I decrease the value of PERCENTAGE, recompile, and execute the program, there is no noticeable difference, in fact I suspect it's the same image, although I can't be sure.

#include
#include

#define WIDTH 400 #define HEIGHT 250 #define TOTAL_PIXELS (WIDTH * HEIGHT) #define PERCENTAGE 0.01 #define BLACK_PIXEL '1' #define WHITE_PIXEL '0'

` int randomBrackets(int n){ return rand()/((RAND_MAX/n) + 1); }

int main(){
	
	char pbm_matrix[WIDTH][HEIGHT];
	for(int i = 0; i < HEIGHT; i++){
		for(int j = 0; j < WIDTH; j++){
			pbm_matrix[i][j] = WHITE_PIXEL;
		}
	}
	int total_black_pixels = 0;
	while((double)(total_black_pixels/TOTAL_PIXELS) < PERCENTAGE){
		int x = randomBrackets(WIDTH);
		int y = randomBrackets(HEIGHT);
		pbm_matrix[x][y] = BLACK_PIXEL;
		total_black_pixels++;
	}

	FILE* img_ref = fopen("bitmap1.pbm", "w");
	fprintf(img_ref, "P1 %d %d\n", WIDTH, HEIGHT); 
	for(int i = 0; i < HEIGHT; i++){
		for(int j = 0; j < WIDTH; j++){
			fputc(pbm_matrix[i][j], img_ref);
		}
		fputc('\n', img_ref);
	}
	fclose(img_ref);
	return 0;
}`

This to open the image file netpbm is needed, and maybe libnetpbm (I don't know, everything is preinstalled on Linux Mint). I'm using the exercise in Rouben Rostamian's book as reference.

EDIT: I'm sorry for the very poor formatting at the top of the code, I can't seem to get the macros to look good

[–] [email protected] 1 points 1 year ago

Thanks for the advice !

[–] [email protected] 2 points 1 year ago

Good points ! Thanks !

[–] [email protected] 1 points 1 year ago (1 children)

I'm happy someone else is considering the time investment. I started using neovim since yesterday for the very purpose of learning key bindings that I deem useful. I'll then move to a config already made with features I like or an IDE. Thanks !

[–] [email protected] 1 points 1 year ago

Those are a lot of good arguments. Thank you.

[–] [email protected] 1 points 1 year ago

Thank you all for your time and valuable input ! I'll be trying out vim and learn a few key bindings then move on to emacs and see what I can do. I'll then try out premade configs like doom and spacemacs and see or the neovim ones and settle on one that has the stuff i want.

 

I'm relatively new to programming, I've been learning C on linux using nano and it's been very fun. I've recently fallen into the emacs/vim rabbithole and I've been watching videos about emacs, Doom, spacemacs, neovim and reading comments about people switching from this or that to another config or editor, and I've been a bit lost on what to do. Then I realised that I haven't done any coding and spent all of my time focusing on editors. So here is my question (which has probably been asked many times) : what is the point of investing so much time learning all of this when there are some IDEs that are preconfigured with all the functionality a programmer would need ? Does learning neovim or emacs actually save time in the long run? I know that they're much more lightweight than IDEs and I've been really enjoying using the terminal much more than my time on IntelliJ, but having an easy out of the box visual debugger, refactoring and jump into functions can be really helpful in the long run I think, especially when starting to write actual large programs. Nano is fun, but not a time saver. Why did you chose your editor?

 
      ' char* strInput =(char*) malloc(sizeof(char));
        int ch;
        int letNum = 0;
        while((ch = getchar()) != EOF){
                letNum++;
                strInput = (char*)realloc(strInput,letNum*sizeof(char));
                *(strInput + letNum - 1) = ch;
        }
        printf("\n");
        printf("%s\n",strInput);
        free(strInput);`

This is the contents of main in a program I wrote that takes an undefined number of chars and prints the final string. I don't understand why but it only works if I press ctrl+D twice, and only once if I press enter before.

does anyone get what's going on? And how would you have written the program?