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 ...
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 ...
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: ...
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'...
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. <...
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 ...
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 ...
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
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 ...
8
votes
1answer
76 views

My malloc() in C using mmap()

My latest school project was to implement malloc(), free(), realloc() and ...
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 ...
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 ...
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 <...
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 ...
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
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: ...
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 ...
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 ...
2
votes
2answers
60 views

Print a double as a decimal with a specified precision

How could I make this code more effective? ...
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 ...
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 ...
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
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
4
votes
2answers
80 views

BigInteger check in C from a string

I have started to learn C. At the time of writing I don't know anything about the language. The following I wrote today in a few hours. Though I do have a lot of programming experience, I find C hard ...
6
votes
3answers
149 views

Finding the longest word without these characters

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 any of these characters: ...
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 ...
0
votes
0answers
44 views

JNI: porting a semaphore data type to Windows

I have this JNI code to review. The demo driver + irrelevant porting code is here. semaphore_impl.h: ...
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, ...
4
votes
2answers
65 views

Computing bezier curves of degree n with recursive functions

I have been looking at homemade CNC and have been wondering how curves are drawn, so I looked into it and found this cool article. I then decided to try coming up with a bezier curve algorithm in C. ...
8
votes
3answers
503 views

Transpose function [closed]

I wanted to write a transpose function for N*N mat without it getting literals or #define values and I want it to compile with ...
7
votes
5answers
297 views

Convert decimal to binary

This program converts a decimal number to a binary number. This is one of my first C programs and I am wondering if I have used the elements of this language properly. Suggestions for improvement are ...
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 ...
1
vote
1answer
59 views

Header-only vector implementation in C

I tried to make a generic, header-only vector thingy I can use in other projects in the future. I omitted documentation comments because it's already quite long. ...
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 ...
3
votes
3answers
101 views

C program to crack passwords

I have implemented a program in C to crack passwords by generating all possible combinations of words ([A-Z][a-z]) up to the length of 5. While the program works, I would like to receive comments on ...
12
votes
3answers
373 views

Huffman tree compressing/decompressing in C

In a past course one of the assignments was to write a program that can compress files using Huffman Tree algorithm, and uncompress the files that the program generates. My design is to count the ...