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.
0
votes
0answers
21 views
6
votes
1answer
28 views
Robust scene manager
I made a simple scene manager in C99. I tried to make it readable, reusable and reliable. I would be grateful if you would help me to improve it. I want to use it for my upcoming OpenGL game. I think ...
2
votes
1answer
39 views
Maximum subarray problem solved with divide and conquer also for the all negative element case
Solving the maximum subarray problem with added cases of finding non maximum non contiguous subarray as well. I used divide and conquer approach and tackled the 'all negative' case by keeping a ...
3
votes
1answer
35 views
7-segment 4-digit display
Is there a better way to organize the methods within this program without compromising the clarity? Running through digits 0-9 with separate functions seems very bulky.
...
8
votes
4answers
920 views
Program to Check If string is Palindrome (in C) [on hold]
Just wrote a program to check if a string is Palindrome. If that's true, return 1. Else, return 0. How can I improve it?
...
1
vote
2answers
79 views
Fibonacci heap in C - follow-up
(See the previous iteration.)
I have incorporated some points made by ChrisWue and refactored my Fibonacci heap implementation:
fibonacci_heap.h
...
1
vote
0answers
31 views
Measuring CPU frequency in *nix
I have this small function for reading the TSC (time-stamp counter) in *nix. Using it seems to report my CPU frequency more or less correctly.
...
-4
votes
0answers
31 views
use malloc instead of mymalloc? [on hold]
I want to change mymalloc() and use malloc instead of it. I would like to know, how I can do it?
...
2
votes
1answer
31 views
Project Euler #7 in C: find 10001st prime using something like Sieve of Eratosthenes
I've gotten a solution for Project Euler #7 in C (find the 10,001st prime). I came up with the very simple algorithm myself (from what I can tell it's similar, if not identical, to the Sieve of ...
3
votes
3answers
67 views
String Compaction Algorithm
I've been working on improving my C coding. I wanted to write two string algorithms:
to trim white space from the beginning and end of a string
to compact a string
I have a few problems with this ...
5
votes
2answers
699 views
Reverse an integer, find the absolute difference, then reverse again
Intro
For one of my university assignments we were asked to take an unsigned int, reverse its digits, find the absolute difference between the original and reversed, then reverse that, and you ...
1
vote
2answers
38 views
Program to let any user run a command
I have a script which can only be run by one specific user on a system. I need to let all users on the system have access to run that script and see the output. But there must never be more than one ...
1
vote
2answers
44 views
Linux C Port Knock Implementation
Compile with: gcc -std=gnu11 -o "portknock" "portknock.c" -lpcap
I did this as a learning experience, and it actually ended up being something useful. I made a ...
2
votes
1answer
24 views
Menu Navigations
My friend requested a navigation menu for his code that he has since he didn't really know how to do it, so I had created one for him. I just wanted to get it reviewed since I'm a beginner with C and ...
-3
votes
0answers
26 views
Error in my C program. Strange data out of nowhere [closed]
I have this code that's far from complete, but I've ran into a problem I just can't figure out.
The code below has it's variables in portuguese and what not, but I think you can understand it pretty ...
3
votes
1answer
153 views
Fibonacci heap in C
(See the next iteration.)
I have rewritten a Fibonacci heap implementation from Java to C.
fibonacci_heap.h:
...
3
votes
2answers
43 views
Tree ADT implementation in C
As a learning exercise, I decided to implement a BST and add functionality to it slowly. I'd appreciate any feedback.
I should also point out that I borrowed the template from the here.
...
8
votes
3answers
883 views
Replace spaces with '%20'
This is my attempted solution to Question 1.3 from "Cracking the Code Interview", 6th ed.
Question:
Write a method to replace all spaces in a string with '%20'. You may assume that the string has ...
2
votes
2answers
80 views
Find numbers between 1 and 10000 whose sum of digits are prime
I have the following C code that finds numbers between 1 and 10000 whose sum of digits are prime and save then to a file.
...
2
votes
2answers
47 views
C permutation generator
I am making a permutation generator in c. Any ideas how I can make it faster?
...
3
votes
1answer
38 views
4
votes
1answer
47 views
Singly-linked implementation in C
I'm a C++ programmer and thought I'd revisit the roots, so I scribbled something really quickly. I would appreciate input on how my C code is looking!
slist.h
...
11
votes
9answers
867 views
Simple string inverter program
I am currently studying c programming, but I'm at a very basic level. So for practice I made a program that reads a string and inverts it. I want to know if the code is readable and how I can improve ...
1
vote
1answer
24 views
Server client for distributed system
This is the code I am using for a distributed system. The code will be used to allow the server to send parts of a (really big) document which will be processed by the connected clients. Please tell ...
3
votes
1answer
39 views
Singly linked list in pure C - follow-up
This is an update for this post.
I fixed all style-issues from the comments, but still have a few questions left:
Someone commented that my last post contained too many functions, which could be ...
14
votes
6answers
539 views
Counting numbers with specific digits
The challenge:
Suppose you are inhabitant of a planet where 1, 7, and 9 are lucky digits. A lucky number for you is a number that contains only your lucky digits in it. For ex: 1, 79, 911, 9917 ...
2
votes
3answers
56 views
Singly Linked List in pure C
I recently learned about linked lists and here is my first try to write one in C. I know it's a lot of code, but I hope someone takes a look. Any tips memory allocation and improvements are welcome.
...
1
vote
2answers
64 views
Efficiently process large (~100MB) structured binary file in C
This question regards the C implementation of the python code posted in this other question of mine, hence the explanation of the task at hand will be the same:
The problem
I need to process the ...
1
vote
1answer
49 views
Read function that properly handles interrupts
This function is meant to be used for reading files. It returns all bytes asked unless EOF is reached. It handles interrupts and returns -1 on errors.
...
2
votes
1answer
32 views
Implementing a sprite batch in OpenGL
I wrote a simple 2D renderer in OpenGL that works pretty well. I can render about 16,000k sprites in 1 draw call if it uses the same texture. I wanted to refactor this code out and put it in its own ...
7
votes
5answers
118 views
A few sorting algorithms implemented in C
I was reading about the elementary sorting algorithms like insertion Sort, selection sort and bubble Sort in Introduction to Algorithms by Cormen and I decided to try and implement it in C.
...
1
vote
1answer
45 views
3
votes
2answers
69 views
Basic shell implementation
Here is a small project to implement a basic shell. It is a personal ongoing project to keep system call usage fresh. It currently does background processes and some basic signal handling.
I am ...
3
votes
2answers
67 views
Generic Singly Linked List in C
I decided to learn generic programming in C (and take a break from templates in C++) by implementing my first simple data structure in C : the singly linked list.
What I'm looking to gain out of ...
1
vote
4answers
60 views
Copy/remove characters “in place” without causing UB from strcpy
I am writing a portable library function, which is a generic "remove characters" function. Language standards used are C11 and MISRA-C:2012.
TL;DR: it should either remove all occurrences of a ...
2
votes
3answers
134 views
Wet Boxes problem: counting points on a triangular grid
As a solution to the B. Wet Boxes problem :
B. Wet Boxes
Bob works in a warehouse which contains a large pile of boxes. The
position of a box can be described with a pair of integers (x, ...
1
vote
2answers
49 views
Printing multiple different shapes on the same line
Whilst scanning my C programming textbook, I saw this practice problem from a very early chapter:
I got to thinking that the problem probably wants you to draw each shape separately, which would be ...
4
votes
3answers
51 views
Convert a number into a different base and return as string
I wanted to write a function that would take a long long int argument as well as a base and it would convert that number into an equivalent number in a different ...
5
votes
1answer
59 views
Constructing a simple shell from scratch
I'm actually doing my whole shell in C from scratch from a Linux computer.
The thing is that I think we all do our best from creating the simplest things that can be explained easily. And I'm not sure ...
10
votes
1answer
417 views
Bash command helper in C
Previously, I had written this program in C++ and asked about it here on Code Review. After spending some time with C++, I desired to become more familiar with its namesake. This is my first C ...
4
votes
2answers
58 views
Reading input from stdin
I read user input from stdin in plain C.
The problem is that I want a sane implementation that is robust to errors and ...
1
vote
1answer
74 views
String compression implementation in C
I implemented basic string compression algorithm that uses the counts of repeated characters. For example: the string aabcccccaaa would become a2b1c5a3. What do you think about this, is there a better ...
0
votes
1answer
59 views
Two over-complicated UART interrupt handlers for SIM900 GSM module [closed]
UARTIntHandler0 interfaces to the USB UART for debugging.
UARTIntHandler1 interfaces to the SIM900 GSM module.
The purpose of ...
11
votes
4answers
592 views
Detecting arithmetic overflow in C with NASM
This snippet is about detecting whether the carry flag is set or cleared. I work on Mac OSX, so my snippet supports Mac only.
First, we need a routine that does the job:
func.s:
...
5
votes
4answers
76 views
Remove specified number of characters from a string
From an exercised in Kochan's Programming in C, following a chapter on C's null-terminated strings:
Write a function called removeString to remove a specified number of
characters from a ...
4
votes
3answers
80 views
Implementation of mergesort in C
I have implemented mergesort in C. Any advice on making it more compact? My merge function seems less than fully optimal.
...
1
vote
2answers
48 views
Simple compression on steroids - now with decompression
A third follow up to the simple compression implementation.
Adopted most of @holroy's suggestions. Main changes:
Compression now uses high-bit to indicate that additional length bytes are still ...
2
votes
2answers
127 views
Phonebook Implementation in C Programming
I have implemented Phonebook in C programming using singly linked list sorted data-structure. This is my first average-major project.
Need some reviews. so that I can improve my coding standards . ...
2
votes
2answers
91 views
Checking battery voltage with ADC and interrupts - which way is best? [closed]
Here are some stripped down versions of the two different programs I am deciding between.
In version one, my state machine is called within the interrupt:
...
0
votes
1answer
52 views
Saturated signed addition
So this a exercise from the book COMPUTERS SYSTEMS A PROGRAMMERS PERSPECTIVE
I need to add two signed numbers and in case it overflows or underflows return ...