Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-3
votes
0answers
8 views

Check if file absorbency/ contains a directory

My code checks if in the path, there is a folder (../codereview/, `/stack``), Would there be a better way to optimize that and with less line? ...
1
vote
0answers
13 views

Taskbar for X11 using Athena widgets

I am developing a simple taskbar for X11 using the Athena widgets. The current code is very limited: it assumes an EWMH-compliant window manager and only adds the initially running windows to the ...
0
votes
1answer
19 views

Noughts and Crosses Version 3

The code's structure has been changed to make the program more readable. I've also commented and split up the program into blocks for better readability as well. The recursion in the player and ...
5
votes
2answers
434 views

Mounting a disk with the DiskArbitration framework

I have the following code that makes use of the DiskArbitration framework to mount a disk to its default location: ...
2
votes
0answers
38 views

Memory managment for RPC code in C

My team has been given care of an old embedded C project. Its main part is a security critical RPC API and I'm trying to create a new design of its internal interfaces to make it more robust against ...
2
votes
3answers
71 views

Printing integers with spaces between the digits

Problem: Given an integer between 1 and 32767 print the individual digits with 2 spaces between them. I am using C How To Program but this is not homework. The book has not gotten to arrays or ...
3
votes
1answer
38 views

Cache-optimized matrix multiplication algorithm in C

I am trying to optimize matrix multiplication on a single processor by optimizing cache use. I am implemented a block multiplication and used some loop unrolling, but I'm at a loss on how to optimize ...
2
votes
1answer
28 views

De-bouncing a (Gray) Rotary Encoder Switch in C

I would like feedback on the correctness and performance of this code. My priorities are also are readability, simplicity and self-documenting code - but I'm happy with those as they are. I still ...
3
votes
1answer
45 views

Noughts and Crosses Version 2

Made the game much more user-friendly than previous version - has an example grid to demonstrate input, Xs and Os are now used. Game can now detect draw. Changed the algorithm to detect winner, it'...
3
votes
3answers
87 views

A simple shellcode that will kill all your processes GNU/Linux x86_64

So I made a simple shellcode that will kill all your process. Now I would like to know, can it be done in some better way? It contains 13 bytes. Thanks for all your feedback Assembly: ...
2
votes
0answers
29 views

Simple generic macro-generated containers

In order to learn macros in C I decided to make a generic data structures generator for other projects that I have in C. The main macros are the following: ...
4
votes
2answers
12k views

Dice Roll Program in C

I've made a dice game that rolls three die, calculates the sum of their results, and asks the user whether he/she thinks the next roll's total will be higher, the same, or lower than the current roll. ...
5
votes
3answers
79 views

K&R C book, Exercise 1-21: Replace tabs with spaces

I'm new to C, just started reading K&R C book, and am working through exercises. This is my solution to 1-21, and as far as I tested it works. Anything that I'm doing wrong, or that it's not ...
1
vote
1answer
32 views

Noughts and Crosses

My first program using C. I would appreciate pointers on how to improve the code. I exit just before turns reach 9 and the grid is filled because it causes all sorts of bugs. The computer is random. <...
1
vote
2answers
86 views

Calculating the minimum and maximum of a byte array [on hold]

I've been working with binary files with this last assignment and part of it was to determine the maximum and minimum byte. Initially this was 2 functions but a bonus portion was to make them into 1 ...
2
votes
1answer
19 views

C Recursive Opendir Wrapper to Sort Directories First (ascending/descending)

A recent post on StackOverflow about a recursive directory listing which produced an unsorted mixed file/directory list, sparked the stray thought of "What would it take to write a wrapper for the ...
6
votes
2answers
133 views

RSA c implementation

This is my first attempt to implement a crypto algorithm. I am using C and gmp to interact with big numbers. Here is my code; you can run it after having linked with the ...
0
votes
0answers
19 views

Need help writing my code for creating an average grade calculator with C [closed]

I'm currently a beginner at C programming. I'm trying to create a calculator where the user inputs letter grades and it outputs the average letter grade AND average GPA. This is nearly complete ...
8
votes
1answer
45 views

Maintain non-persistent database for books

The following program displays a menu, and prompts the user to choose an option. Options include to add a book, delete a book, view all books, and to exit the program. (Note that the actual code to ...
3
votes
2answers
119 views

Circular Queue in C for an embedded project

I wrote a simple circular queue. (in order to store characters because of the fact, that I am using UART through the DMA and sometimes my printf's override each other) I am looking for some review, ...
9
votes
5answers
2k views

Basic C copy file implementation

I'm a java programmer by trade and starting to learn C/C++. I'd appreciate any pointers on glaring issues with my code style which is acceptable in java but not in C. I feel like open_files is ...
8
votes
1answer
76 views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
4
votes
3answers
4k views

Find the smallest number in the first array that is not in the second one

I have solved the given assignment below is the question and getting correct answer. but my question is is there any way to reduce the complexity of my code or there is any other efficient way to ...
0
votes
1answer
33 views

Two functions that move array elements [closed]

These two functions act on a stack, an array of integers (whose first element is the top of the stack, LIFO). The first function retrieves the first element and puts it at the end. The other is the ...
0
votes
2answers
65 views

Convert number to X base

As an educational exercise, I would like to make this code more efficient, with fewer lines, without using other standard functions. The goal here is to convert a number to X base and display it, (...
3
votes
2answers
82 views

Removing commented dead code without removing the legitimate comments

This question is the real question asked on StackOverflow. I'm here to review my answer and see how can I optimize it. Here is the answer text: This is a basic approach, but it proposes a proof of ...
4
votes
3answers
81 views

if you gaze long enough into strtok, strtok will gaze back into you

The tokenise function below splits a given string at the indicated delimiters. As with strtok, it modifies the string by adding <...
2
votes
3answers
4k views

string to integer (implement atoi)

Implement atoi to convert a string to an integer. Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is ...
7
votes
4answers
637 views

atoi implementation in C

I'm looking for feedback on my atoi implementation here in C. Any feedback would great. I made my own atoi for fun and to learn ...
0
votes
1answer
46 views

Polymorphism and inheritance in C99

In the following code I have created the something like the behavior of inheritance and methods in C99 (without vtable). The code compiles without any warnings even with ...
5
votes
1answer
131 views

K&R Exercise 1-6 & 1-7: working with EOF

I'm working through K&R at the moment and I've found my first exercise that seems to be a good use for my first CodeReview post. Exercise 1-6 - Verify that the expression ...
3
votes
4answers
801 views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. The recommended way is: int *p; int n=10; p = malloc(n*sizeof *p); You can use ...
6
votes
1answer
79 views

Function to print a double - exactly

Rarely is the exact value of a double needed to be printed and only its leading significant digits, after rounding, are needed. It is a curiosity to see the exact ...
1
vote
4answers
113 views

Read a palindrome of unknown length

I have a task to write the function: int read_palindrome(); // input comes from stdin which will read one line from standard input and returns 1 if the line is a ...
2
votes
2answers
60 views
5
votes
8answers
313 views

List implementation in C

I tried to implement a Python-esque list in C. Having not really used C in anger, I'd like some pointers on style and error handling in particular. Header ...
0
votes
1answer
29 views

Simple text-based inventory manipulator

I was bored so I crapped out a simple game that responds to commands and manipulates an inventory. I am interested in other possible ways to handle the inventory, and I think I went overboard with ...
1
vote
1answer
31 views

Simple unit test in C of input using freopen

Here is an initial attempt at unit test of user input in C. The thing that feels unusual is the use of freopen to send the test data to stdin. Are there better ways to implement this kind of test? <...
4
votes
2answers
11k views

Timestamp function with millisecond precision

I want to be able to print timestamps with milliseconds precision and time_t doesn't provide this. I also want the code to be portable, so operating specific ...
4
votes
3answers
82 views

Linked List written in C

I have been learning data structures and dynamic memory allocation in C. As a learning experience, I have written this linked list implementation. I really appreciate the feedback I've received on the ...
3
votes
2answers
88 views

Change Arithmetic Right Shift to Logical Right Shift

The following code is a solution to a textbook (Bryant&O'Hallaron: Computer Systems A programmer's Perspective 2nd Ed) problem in bit-level data manipulation (attempted for the challenge, not a ...
1
vote
3answers
76 views

Is a string a bit string

New to the C language. Which design mistakes have I made in my first C program? Or what can I improve? Any little detail is appreciated. Note: I have experience in multiple coding languages. (this is ...
5
votes
1answer
3k views

A simple NAT library

I've created a simple NAT library, with four essential functions: Find the UNPN device (the router in my case). Get the external IP address. Add a port forwarding entry. Delete a port forwarding ...
4
votes
2answers
81 views

Hangman v2 written in C

This is a follow up to my previous Code Review, and I have incorporated feedback I received in this revision of the code, along with some other improvements. I would appreciate your feedback on this ...
2
votes
1answer
107 views

Simple Malloc Implementation

I've written an implementation of malloc, realloc, and free. I wanted to make a ...
4
votes
2answers
54 views

Frame limiting in an SDL game

I am a relatively novice programmer, and I am taking steps into graphics programming. I am writing a quick pong clone and want to cap the FPS to save system resources. This is how I have implemented ...
4
votes
2answers
109 views

Sorting an array of numbers by descending frequency

Somebody asked me to create a code that orders unique numbers of an array according to their frequency, ie: {1,3,3,4,4,4,4,4,2,2,5,5,5,5} to ...
3
votes
2answers
36 views

Implementation of getdelim

Note: I wasn't trying to follow the POSIX getdelim signature exactly. I needed to add the consume argument for a project I'm ...
2
votes
1answer
65 views

Finding the longest word without these characters follow-up

Here I asked this question: My goal is to go through the list of all English words (separated by '\n' characters) and find the longest word which doesn't have ...
3
votes
1answer
65 views

Hangman written in C

I would like your feedback on any improvements that can be made to this Hangman game I have written in C. Specifically, improvements in terms of runtime and code organization. This game was a nice way ...