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.

1
vote
1answer
23 views

Dynamically-resizable array implementation, for use in a game-dev-related library

I've been working on a library that includes a list-like structure, which I use internally multiple times to store different types of structs. However, I'm not entirely confident with my ability to ...
17
votes
1answer
179 views

Brainfreeze: A Brainfuck compiler in C

BrainFreeze This is my implementation of a brainfuck compiler in C. The instruction to build/run the project (GitHub repo) can be found here. I am first converting the brainfuck source to x86 ...
7
votes
2answers
111 views

Pausable Timer Implementation for SDL in C

Problem I've written a timer module in C for an SDL game. I'd like to get some eyeballs on. I wrote this for 2 requirements: I needed a timer that would signal on an elapsed interval, AND that was ...
9
votes
1answer
70 views

HashTable using C

Introduction This is my first attempt to mess with memory allocation using C and create something close to a python dictionary. Coming from a high level programming language like Python or Java, I am ...
1
vote
0answers
30 views

Convolutions with shared memory in CUDA

I am writing a noise blur convolution kernel in CUDA ...
5
votes
2answers
81 views

Implementation of memset_s based on C11 standard

The following code attempts to implement memset_s() based on section K.3.7.4.1 of the ISO/IEC 9899:201x N1570 draft: ...
13
votes
3answers
147 views

Detecting unicorn and dinosaur compilers

Rumor is that the next version of C will disallow sign magnitude and ones' complement signed integer encoding. True or not, it seems efficient to not have to code and test for those rare encodings. ...
11
votes
2answers
83 views

Dynamic vector of void* in C

I have implemented a simple dynamic vector library in C. It is a header-only library. Full library listing - void_vector.h: ...
3
votes
2answers
60 views

Macros for bitsets / bit-flags in C

Context: I have some C code that uses a lot of bit-flags. The flag-sets may have a couple of hundred members. Currently these flags are defined as a 32-bit mask that must be applied to a specific ...
2
votes
1answer
45 views

segstr - Get delimiter-separated segments from a string in a non-destructive method

I wrote my first useful function in C which can be used in a different variety of situations as an alternative to common code logic. segstr (originally named ...
4
votes
1answer
72 views

Basic queue implementation in C

I'm practicing data structures in C and I implemented a queue based on its description: ...
2
votes
1answer
72 views

A basic calculator in C that uses a loop

I have created a program that forms a basic calculator in C which includes the basic operations like addition, subtraction, multiplication and division. But in this case I decided to use a Do-While ...
2
votes
2answers
141 views

Convert exam marks to overall grade

I have started working on the code below here. I want to practice my C coding skills. It is a grading program: given a set of subject marks, calculates the sum, average and it converts the computed ...
4
votes
1answer
87 views

A command-line unbeatable Tic-Tac-Toe written in C

I'm trying to learn programming and this Tic-Tac-Toe is one of my first projects. The user gets to start first as 'x' or second as 'o'. Please give me any criticism you find on the code and give ...
0
votes
0answers
50 views

Read consecutive blanks in array

I am writing a function that reads all consecutive blanks in a string, moves the pointer to the next non-blank char, and return a struct "token" that contains the blanks it found. The main function ...
1
vote
1answer
46 views

Rijndael S-box for a string of bits

My question is more of a "can someone give me tips" rather than "can you do it for me" I have been writing a C code implementation that takes a 32-char String in the form of binary (supposed to act ...
3
votes
2answers
83 views

Splitting C string without modifying input

I wrote this after using strtok_r and needing something similar that can copy the input string and handle multiple characters in the delimiter. Its functionally ...
0
votes
2answers
72 views

Loan calculator in C

I wanted to create a loan calculator, but the code I could think of was using 3 functions, and calling them and getting result. But I felt it was easy but bad code because I thought this can be ...
1
vote
1answer
31 views

Removing trailing whitespace from input lines

I'm going through the K&R C book (coming from Python) and am on exercise 1-18, which states: Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely ...
2
votes
1answer
26 views

Create a histogram of the lengths of words

I am reading through K&R C 2nd Edition, and I am on exercise 1-13. The exercise is to write a program to print a histogram of the lengths of words in its input. I wrote a program that successfully ...
0
votes
1answer
69 views

Fizzbuzz but without if

Code first, elaboration later: ...
2
votes
0answers
42 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
26 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 ...
3
votes
0answers
74 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
77 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
52 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 ...
2
votes
0answers
44 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: ...
3
votes
1answer
50 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'...
1
vote
1answer
35 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. <...
2
votes
1answer
21 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 ...
8
votes
1answer
50 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 ...
5
votes
3answers
91 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
2answers
87 views

Calculating the minimum and maximum of a byte array [closed]

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 ...
9
votes
1answer
115 views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
10
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 ...
0
votes
1answer
34 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 ...
4
votes
3answers
83 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 <...
0
votes
1answer
52 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 ...
0
votes
2answers
71 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
3answers
105 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: ...
1
vote
4answers
134 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 ...
6
votes
1answer
84 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 ...
2
votes
2answers
64 views

Print a double as a decimal with a specified precision

How could I make this code more effective? ...
1
vote
1answer
36 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 ...
3
votes
4answers
931 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 ...
1
vote
1answer
40 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
3answers
86 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
97 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
78 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 ...