2 ms·
Begginer in C. Critique my code and give ideas?
- zeved 12y agoHello HN. I'm trying to learn / relearn C (for real this time). Wrote this little tool for linux and I would like some feedback. Also, if you could give me some ideas for future small projects that would give me more experience in C... thanks!
- plikan13 12y agoint get_number(char buffer[]) { long int i = 0; char *p; if(fgets(buffer, sizeof(buffer), stdin) != NULL) { sizeof(buffer) will always be 4 (or 8 if you compile 64 bit) because sizeof(pointer to char) is 4 (or 8). It will NOT be the size of the buffer that you pass as an argument. To fix this problem you need to change the function to int get_number(char buffer[], int buffer_size) Also the buffers that you pass to this function seem to be too small.
- zeved 12y agothank you very much. i appreciate it!