Questions tagged [c]

C is a general-purpose computer programming language used for operating systems, games, and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.

Filter by
Sorted by
Tagged with
3 votes
1 answer
74 views

Portable integer to/from little endian conversion in C

Integers need to be converted to a byte array of defined endianness to be reliably and consistently saved and transmitted, and converted back to be accurately received and read. The goal is to be as ...
3 votes
4 answers
97 views

Trigonometric functions calculator

This is a basic 6 trigonometric functions calculator that I will incorporate into my main calculator project. It works as intended, but the BUILD MESSAGES issue a warning, the warning being: Warning: '...
10 votes
7 answers
2k views

Unidirectional linked list in C

I'm learning algorithms and I wrote the single-directional linked list implementation in C. I need a code review of what can I improve in my code and I want to make sure there are no possible memory ...
  • 101
3 votes
2 answers
116 views

K&R Exercise 5-11. Modify the "detab" - to accept a list of tab stops as arguments

So far I have reached chapter 5 of the K&R Book, Edition 2 from which I have been learning C. I spent a few days thinking of a solution to this program. I wrote two or three versions of the same ...
-5 votes
0 answers
21 views

I have problem with programming code on language C. What should I do so that when c and b are equal, the condition is fulfilled? [closed]

...
6 votes
4 answers
408 views

K&R Exercise 5-10. reverse Polish calculator

I have been learning C with K&R Book 2nd Ed. And well, so far I've gotten to chapter five, and I've been dealing with pointers/command line arguments. I came up with the following solution for the ...
3 votes
1 answer
53 views

Drawing a pair of triangular walls for CS50 Mario

This is my code for the CS50 Mario (more comfortable). Answers can be found all over the net however I wrote this myself. I would like to refactor to its maximum potential (just for my own improvement ...
9 votes
1 answer
378 views

Intrusive linked list in C

I've been working on an intrusive linked list for the past few days for a personal project and I would like to have some feedback on it. :) Personally, I would have preferred to make ...
4 votes
1 answer
205 views

Simple slab allocator in C

Here is the plan: a slab takes up 1 page and it has PGSIZE / blocksize amount of blocks the minimum blocksize is 8 bytes, otherwise the pointer to the next block ...
0 votes
1 answer
71 views

Temperature Scale Converter in C

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
2 votes
1 answer
93 views

K&R Exercise 1.22 - "fold" long input lines

Until recently, I decided to go back to Chapter 1 of the K&R Book, Edition 2, to try to "improve" the code I've already done. I have also made some changes since I was limited to just ...
3 votes
2 answers
110 views

K&R Exercise 4-6. Add commands for handling variables

For the following exercise (Chapter 4, Ex-4.6) of the Book (K&R 2nd Edition): Exercise 4-6. Add commands for handling variables. (It's easy to provide twenty-six variables with single-letter ...
2 votes
1 answer
152 views

Thread scheduler in C

I have made a simple round robin scheduler that switches between threads in ptable array. Currently it's only for 1 CPU, so there are no locks at the moment. But ...
8 votes
3 answers
676 views

K&R Exercise 3-3. Expands shorthand notations (e.g., a-z to abc..xyz, 0-9 to 012..789)

I have been learning C with K&R Book 2nd Ed. So far I have completed quite a few exercises. For the following exercise (Chapter 3, Ex-3.3): Exercise 3-3. Write a function expand(s1, s2) that ...
4 votes
1 answer
118 views

Need for matrix multiplication speed

I need help to make matrix multiplication in C run as fast as possible. On my AMD Phenom(tm) II X6 1090T, my program multiplies two square singe precision 4096x4096 matrices in about 6.9 seconds. ...
2 votes
1 answer
44 views

Iterate over a process' maps file

The following logic provides iteration over /proc/<PID>/maps for a Linux process. What I'm primarily (though not solely) interested in for this review is ...
2 votes
1 answer
67 views

Hash table C implementation - Separate Chaining

I've written a C implementation of a hashmap of strings including the basic operations and a strategy for handling hash collisons. Additionally, I've included some tests, specifically for cases ...
  • 107
6 votes
4 answers
606 views

CS50 pset1: credit card classification and checksum validation

I wrote the following code for the cs50 pset1 credit and it passes all the checks. However, I think that it is too long (specially the last part) and would like to improve it. I would be very grateful,...
7 votes
3 answers
1k views

K&R Exercise 1-19. "detab" program that replaces tabs with the appropriate number of blanks

I am trying to do a few exercises from the K&R book from the first chapter - exercise 1-19. I have to write a program "detab" which replaces tabs in the input with the proper number of ...
4 votes
1 answer
44 views

Linux netlink kernel socket arp cache getter (similar to ip ne)

...
  • 141
6 votes
3 answers
107 views

Simple selection_sort in C

I study algorithms, and I try to implement each algorithm in C (Perhaps it would be better to choose C++, but okay) Here is my implementation of sorting by choice. How would you rate it? To be honest, ...
2 votes
1 answer
34 views

Sending and receiving files in C win32 using a socket

I have a piece of code to send and receive files on Windows with C. Is this the right way to do it? And am I guaranteed that the full file will be sent and received? Receiving function: ...
  • 83
5 votes
2 answers
83 views

Basic Linked List C implementation

I've written a singly-linked list of characters. This is my 3rd C program and I'd like some feedback on what I can improve on in any aspect whatsoever. If you'd prefer to look at the repo directly it'...
  • 107
3 votes
2 answers
106 views

Ray tracer in c running slowly

I was learning C the past few days and decided to make a mini project to get a better feel for it following the Ray Tracing In a Weekend Series. I got it working however I feel like it is pretty slow ...
6 votes
2 answers
151 views

(Rev. 2) Type-generic queue implementation using singly linked lists

Thanks to the extremely helpful comments and answers from the original post, I've improved the interface and implementation of this general-purpose queue library. Improvements include: Fixed memory ...
  • 535
9 votes
2 answers
806 views

Sudoku Solver in C without recursion

I am trying to learn backtracing , so i wrote program for Sudoku It solves sudoku in approx. 1 ms in online c compiler but this one sudoku puzzle is taking approx. 35 sec in that online c compiler ...
  • 271
3 votes
4 answers
122 views

Read arbitrary length strings in C

This is a classic thing to want to do since it's in C that one doesn't have the std::string of C++ and input of Python. I ...
0 votes
1 answer
75 views

duplicate an open file descriptor [closed]

My program implements a function similar to `dup2'. I would like you to please find any problems with the code and what I could improve. code: ...
1 vote
1 answer
164 views

Virtual memory manager in C

Virtual Memory manager that has functions, mappage, unmappage, remappage If the physical ...
11 votes
4 answers
965 views

Type-generic queue implementation using singly linked lists

Simple lightweight queue implementation using data size registration and singly linked lists as the underlying type Update #2 ...
  • 535
2 votes
1 answer
72 views

Bitmap page allocator in C

Bitmap page allocator that scans the bitmap linearly looking for size amount of pages. Everytime it founds a free page, it check if the next ...
2 votes
1 answer
96 views

The receive function for telnet client

This is a follow up question to Send and receive functions for telnet client. I am designing a simple wrapper around the telnet client using libtelnet for text-based communication to a telnet server. ...
  • 429
3 votes
1 answer
142 views

UEFI bootloader

UEFI bootloader. It reads the file kernel.elf on the disk image, reads through the program headers, copies the LOAD segments into memory, and finally calls ...
3 votes
1 answer
57 views

Bloom Filter C implementation

this is my first C program. It creates a bloom filter from an array of N char arrays and k hash functions. I'm not particularly ...
  • 107
4 votes
1 answer
149 views

Send and receive functions for telnet client

I am using libtelnet to design a telnet client by sending text commands to a telnet server and receiving text responses. I am utilizing telnet-client.c. For simplicity, I made send and receive ...
  • 429
0 votes
1 answer
46 views

timeConversion - C function to convert 12-hour AM/PM format into military time [closed]

I have written a program in C, which given a time in 12-hour AM/PM format, converts it to military time (24 hours). Function Description The timeConversion function should return a new string ...
2 votes
1 answer
42 views

Priority Job/Task Queue for Linux (sockets and multithreading)

Preface Please review my implementation of a job queue for linux/unix systems. This is my first time coding in C, although I have quite some experience in C++. I know this is a moderate amount of loc, ...
2 votes
1 answer
68 views

C dynamic strings

In the process of writing a compiler, I wrote this dynamic string library to help with keeping track of heap allocated strings and to have an easy way to format them. Note: The macros ...
2 votes
1 answer
149 views

C Program - Camel Case (creates or splits camel case variables, methods and class names.)

I have written a program in C, which does the following operations: creates or splits Camel Case variable, method, class names. Input format Each line of the input file will begin with an operation ...
2 votes
0 answers
47 views

Virtual memory manager, physical memory manager and buddy allocator

I'm writing memory manager for my toy operating system and I would like to get some feedback. There is physical memory manager, which uses bitmap, virtual memory manager which uses buddy algorithm for ...
  • 21
7 votes
3 answers
129 views

Program that calculates the first n powers of x

I am a beginner. I wrote a C program that calculates the first n powers of x and I don't even know if this is legit C code or ...
2 votes
1 answer
76 views

Portable noreturn in C/C++ between compilers

I'm writing a C/C++ (intended to also be valid C code) for having a noreturn macro variable as widely portable as possible between C and C++ compilers. ...
  • 163
3 votes
3 answers
100 views

C program that splits the string based on a character

I tried and made a program using my beginner knowledge of C to split a string into multiple sub strings. I just wondered how languages like Python and Javascript implemented the ...
  • 71
1 vote
1 answer
83 views

Shell implementation in C

I made a small shell implementation in C. It reads stdin and executes the command. It can also take in a file name from argv and execute all the arguments in the ...
-1 votes
1 answer
43 views

Packing several values into a byte buffer [closed]

I'm packing several values from a struct into a buffer to send them over Bluetooth. I don't want to send the whole struct and I also don't want to deal with padding, so I'm copying just the values I ...
  • 159
3 votes
1 answer
95 views

Connect4 game with "Minimax-AI" and raylib

I am just trying to understand the minimax algorithm better and how it works, so I made this basic connect4 game with raylib. It works fine, but I think there must be some kind of flaw in the logic, ...
2 votes
2 answers
77 views

Maze SOLVER in C

a maze solver in C. I have not included the maze generation code because i'm not looking for a review on that in this post, but the maze solver operates on a 1D array of cells, for more info: Maze ...
2 votes
2 answers
95 views

Astronomical calculations in C for python bindings

I've started teaching myself c/c++ with the intent of being able to writing python bindings to c code. I have a c library used ...
12 votes
4 answers
2k views

C generic dynamic array (using preprocessor)

I wrote a generic dynamic array using the preprocessor. My use case for it is a compiler I'm writing that uses dynamic arrays a lot, and my current void pointer implementation is becoming a bit hard ...
1 vote
0 answers
36 views

Maze generator in C (part 2)

Maze generator in C. This is part 2 of this I changed everything I was told I should in the part 1 of the review. I also added functionality to be able to step through the generation of the maze, or ...

1
2 3 4 5
75