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
votes
0answers
15 views
Pushbutton password for arduino [on hold]
I am modifying the arduino Debounce code found in the library for this project. The objective is to use two push buttons and when the first one in pin number 2 is pushed then add a to password string ...
0
votes
1answer
34 views
Mergesort performance in C
I have two questions about my code:
Are there any performance improvements in this implementation or generally (register int ?) that I could make?
What could I ...
-4
votes
0answers
17 views
-1
votes
0answers
21 views
How to insert new item into linked list in C (at the end of the list) [on hold]
I'm trying to get my head around Linked Lists in C, and have ended up confusing myself.
My question is: Is this correctly inserting the different people at the ...
3
votes
2answers
30 views
Compare Two Files
One of the K&R exercises is to write a small piece of software to compare two files and print the first line in which they differ.
Here is my attempt:
...
-2
votes
0answers
15 views
Implementing Play Again? in the Guessing Game Program (C Programming) [on hold]
After researching for a while and trying and adding another while, I could not figure out how to implement the Play again section...
The instructions are to create a guessing the number game with 6 ...
3
votes
2answers
47 views
pthread_cond_wait() based multithreaded Linux daemon skeleton
I'm trying to design a multithreaded daemon for an industrial automation related project.
The daemon will be using a number of 3rd party libs like MQTT, mysql, etc..
My idea is to have worker threads ...
1
vote
1answer
27 views
Enforce exclusive order of four processes using semaphores
I am on the learning curve of C and its capabilities. Below I have tried to create 4 individual programs where the execution is always in order (program 0,1,2,3).
About the program
Program #0 is ...
4
votes
1answer
36 views
Word Counter Project
I recently read K&R The C Programming Language and wanted to write a small program to count the occurrence of each word in the input (std-input - I piped a file with all shakespeare pieces in ...
1
vote
1answer
30 views
Hash Map Library for any type (Void Pointers)
This is a hash map library for C that stores void* pointers with char* strings (null terminated) for keys
...
-1
votes
0answers
14 views
Scrub a file of characters and replace with strings [closed]
I'm new to C and programming in general, so please be gentle. I've searched similar threads, but I can't seem to pin down what is exactly causing me issues.
I'm trying to read an HTML file (however ...
8
votes
2answers
192 views
Scoring and grading answers against an answer key
Intro
I won't lie this is for a university assignment (don't worry the code is in working order), and while I could hand it in as-is and receive full marks I feel like there is probably a more ...
2
votes
2answers
49 views
FIFO getch/ungetch Functions
I'm currently working myself through K&R and just read about implementing getch() and ungetch().
In K&R these ...
5
votes
2answers
222 views
Stack implemented using a single linked list
I am studying data structures and I have implemented a stack using a linked list.
stack.h
...
-2
votes
0answers
13 views
delete all elements in a singly linked list [closed]
I am trying to free all of the memory in my SLL, but I can't seem to figure out what I am doing wrong...I keep getting memory leaks when ran with valgrind and seg faults...Here is my code:
...
6
votes
0answers
40 views
Unity3D native iOS plug-in to read pedometer data
I've made a plug-in for Unity3d for iOS. The plug-in's job is to get the Pedometer data from history within a specified period of time and return that to Unity for later use. I am confident in my C# ...
4
votes
2answers
90 views
Machine independent C library for printing the binary representation of data types to stdout
I'm curious as to peoples thoughts on this small library I have made. I noticed there are no functions in the C standard library to accomplish this task.
I have tried to make the code machine ...
7
votes
2answers
105 views
All arithmetic operator functions (+, -, *, /, %) coded only using bitwise operators in C
Here's all the functions in C that does all the arithmetic operators without using arithmetic operators themselves, mostly using bitwise operators. Recursive functions and comparison operators are ...
4
votes
4answers
123 views
Simple singly linked list implementation in C
I have implemented a LinkedList with the ability to add, get elements from a particular position and ability to show all the elements in the array in to the console ...
7
votes
1answer
49 views
Function to wrap words in a text editor without breaking them
These are 3 functions I created in C language to read in a text file, remove the carriage returns from it in order to display on the screen, and display the file on screen wrapped with the words of ...
3
votes
1answer
39 views
Positive and negative FizzBuzz
I want to eliminate code duplication in my Fizz-Buzz like program. Any ideas?
...
5
votes
3answers
398 views
Slow prime finder
This program runs in about 1.65 seconds on a 1.65GHz dual core processor.
I compile it with:
gcc -Wall -o ./program ./program.c -lm
Are there any optimizations ...
8
votes
2answers
78 views
UNO for ncurses
I've been teaching myself C for the last few months. As a learning exercise, I set out to write an ncurses implementation of the classic card game Uno, mostly because it was was one of the simpler ...
5
votes
1answer
71 views
Program to tell which if any of three numbers is in the middle
I wrote this program, and it does what it asks, but it's so big and ugly. What can I change?
Some examples:
...
7
votes
1answer
311 views
Turning music into an image
I was bored, so I wrote something that could turn .wav files in to .bmps:
...
-2
votes
0answers
37 views
C - Terminal Like Application with Pretty Limited Functionality
First of all, I will admit that this is a university project. I have submitted it but I am really interested in how I could make it more efficient or even cleaner. I don't expect anyone to actually go ...
-1
votes
1answer
47 views
Server listening for program sockets
Essentially I have a server that will be listening for sockets in other programs seeking a connection:
...
0
votes
1answer
48 views
Fixed Point Number to String
I recently learned about using fixed point arithmetic on embedded systems without floating point hardware, so I decided to code it. I tried to write in good style, but emphasized speed over style.
...
1
vote
1answer
43 views
Celsius and Fahrenheit Converter
I'm very new to programming in C and I attempted to make a program that converts temperatures to and from Fahrenheit and Celsius. I have been running the program and I have realized that not all ...
1
vote
0answers
42 views
lut_atan() implementation to calculate atan() fast [closed]
To calculate atan() fast I've coded lut_atan() implementation. Can anyone help me to find out why I'm getting "not consecutive access" message from GCC?
...
2
votes
1answer
34 views
JSON C pull parser
Back in the day in addition to DOM and SAX parsers for XML another parser type was relatively popular -- pull parsers. Recently I was looking for a JSON parser and figured that most JSON C parsers are ...
1
vote
1answer
38 views
Printing a singly linked list with time complexity O(n) and space complexity O(sqrt(n)) [closed]
My aim is to write a method which prints contents of a singly linked list in reverse order with time complexity \$O(n)\$ and space complexity \$O(\sqrt{n})\$. The best I could come up with is to store ...
6
votes
1answer
87 views
A C function for returning the address of the calling function
Suppose you are given two functions, foo and bar, and neither of them are inlined. Now, if ...
3
votes
1answer
52 views
Video frame to Minecraft map colors
I'm still somewhat new to C, so pardon me for any silly mistakes I've made.
I'm trying to convert video frames into Minecraft map colors using JNI and ...
1
vote
1answer
39 views
Data structures in C (doubly linked list)
NOTE: Added corrections based on feedback. The DobLLRemoveNode function now works properly. It will stop if the given value is NULL and it will not set the tail to the head unless they are the same.
...
4
votes
2answers
84 views
Draw multiple objects
The OpenGL tutorial that I was following only used a single model to demonstrate various points. I wanted to draw more than one model. After some research, I came to the conclusion that I needed to ...
1
vote
0answers
59 views
Complete async OpenSSL example
I am trying to create a fully async example of a client and server using SSL.
I think these are the required assumptions:
Connecting may require socket readability and writeability notifications.
...
1
vote
1answer
30 views
Get radial distance between vector1 and vector2
A small script to calculate total units of distance between two vector entities. Especially useful in games and grid snaps, inventory snaps etc..
...
2
votes
1answer
53 views
Shortest path from U to V using at most k nodes
I'm trying to solve a problem that asks for a shortest path between two cities with at most k nodes.
The first line of input has the number of test cases. On the second line 3 integers are given, ...
3
votes
1answer
31 views
PWM wave generation
This code takes a integer x of range [0,127] as input, returns an array of four 32-bit integers, with x bits set.
I'm trying to ...
3
votes
2answers
70 views
Parsing an ini file
I have written a basic ini file parser in C. It won't support big ini files, and isn't very fast when fetching configuration values, but should be enough for small ones.
I couldn't find "proper" ...
2
votes
1answer
47 views
Optimize program to test for divisibility of numbers 3.0
This is a follow up on my previous question.
JS1's answer suggested that I should use a precomputed table containing all permutations of the lowest valid number for each number between 1 and MAX. It ...
-1
votes
1answer
44 views
Read Log from external memory
I log records in external memory. Every record takes \$2\$ bytes. Now I need to read \$N\$ last records in chunks of \$18\$ bytes, so I did something like this.
...
-2
votes
1answer
32 views
Finding the smallest prime number greater than a user input [closed]
As it says in the title, I am trying to find the smallest prime number greater than my input, 'input.'
I have to use the following guidelines when creating my code...
You program should implement ...
4
votes
2answers
137 views
Reverse all lines in a file
The script below should open a file, read and reverse every line, then overwrite the source file.
...
3
votes
1answer
60 views
Testing for divisibility of numbers - follow-up
(Here is the follow up question)
I had another go at trying to speed up my program described in my previous question.
JS1's answer was particulary helpful and now my code is only about 20% slower ...
1
vote
1answer
28 views
Searching and replacing text
Simple Playlist Modifier
This program is a search and replace program for text based files. The main goal of the program is to replace directory paths to music files.
The idea is to have the program ...
8
votes
2answers
170 views
Simple extractor for Quake-2 PAK archives
I was fiddling with the source code of Quake-2 today and at some point wanted to extract files from the .pak archives used by the game. Since I couldn't find any ...
3
votes
1answer
92 views
Allocating matrices for in-place modification
This code seems to be working. I am allocating matrices on the stack and passing them to functions to modify in place. Is this a standard practice, or am I doing it wrong?
Header:
...
2
votes
1answer
22 views
Server that accepts HTML and PHP requests
For the Harvard cs50x MOOC I have completed an assignment in which a C server framework that functions like a barebones apache server is provided, to be finished by the student.
The below code will ...