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
1answer
38 views
Add to a variable multiple in cells variables
I have code that is used to add all cells of a tab to a var:
...
3
votes
1answer
27 views
Pseudoportable C script pattern
From time to time, while working with a command line in *nix family of operating systems, we have to write those scripts doing a rather specific task. Usually we use ...
-12
votes
0answers
38 views
-5
votes
0answers
22 views
Guessing Game in C (help me) [on hold]
Write a C program that is randomly generates a number between 1 and 15,
and then the user is asked to guess that number. The game gives the user
three chances to guess before user loses.
In case the ...
-4
votes
0answers
23 views
Segmentation fault in Trie ADT and help in search/insert [on hold]
I have a trie ADT which I think should work(atleast the insert). It inserted all the words at first, but after revisiting the code it produces a segmentation fault at "(!curr->index[charIndex])" on ...
3
votes
1answer
51 views
ARP implementation
I am a beginner in C and wrote this code to implement ARP.
3 threads are present - one to respond/receive any ARP packet targeted to me, one to refresh the ARP table on a periodic basis, and one to ...
3
votes
1answer
42 views
Inserting a parenthesized nickname
Given two strings, for example
s1 = "Valentino Rossi" (which may contain as many spaces between the 2 words as I like)
s2 = "Vale"
I have to create a function that requests these two ...
3
votes
1answer
17 views
Given a string, print another one without a given char
My aim is to write a C program (I must create a function) that, given a string and a character, returns another string without the given char value.
For example: ...
1
vote
2answers
35 views
2 ways to print a half-pyramid
I wrote this bit of C that prints a half-pyramid,
*
**
***
****
Here's the main body:
...
-3
votes
0answers
19 views
4
votes
1answer
33 views
Initializing an EGL display
I'm somewhat new to writing real-world projects in C, so I'm not familiar with best practices and standards. I'm writing code dealing with EGL and OpenGL, and some setup calls might fail for reasons ...
5
votes
1answer
47 views
Simple pager in C
I have written a simple pager in C. It works fine for most things, but I'd like to know how it can be improved. Specific things I'm looking for are if there are size and/or speed improvements to be ...
-4
votes
0answers
19 views
C: Where is my mistake trying to solve this simple riddle? [closed]
I'm trying to do a simple problem in C that goes like this:
Any integer P, such that 0 < P < N, splits this tape into two non-empty parts: A[0], A[1], ..., A[P − 1] and A[P], A[P + 1], ..., A[N ...
2
votes
3answers
82 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
2answers
37 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:
...
3
votes
2answers
50 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
30 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
38 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
33 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
...
8
votes
2answers
222 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
227 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
...
6
votes
1answer
68 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
102 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
107 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
130 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
41 views
Positive and negative FizzBuzz
I want to eliminate code duplication in my Fizz-Buzz like program. Any ideas?
...
5
votes
2answers
404 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
84 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
74 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
315 views
Turning music into an image
I was bored, so I wrote something that could turn .wav files in to .bmps:
...
-2
votes
0answers
38 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
50 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
49 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
45 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
49 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
40 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
89 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
86 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
68 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
54 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
33 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.
...