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
31 views
Calculating e^x by math.h and by own means
For this program, the user needs to enter an exponent and the program will calculate \$e\$ (Euler's number) to the power of the exponent the user inputs.
This is done by two ways:
By the math.h ...
4
votes
2answers
46 views
Escape some char in a byte array
I am trying to construct a binary message packet. It needs to escape binary value 0 by appending extra 0 in front of it:
...
2
votes
1answer
28 views
Ordered doubly-linked lock-free list
I'm implementing a lock-free ordered doubly-linked list based on heavily modified paper entitled Split-Ordered Lists: Lock-Free Extensible Hash Tables by ORI SHALEV. My main concern is correctness of ...
5
votes
2answers
250 views
HackerRank “Flowers” challenge
I'm fairly new to C and wanted a general review of this code. It's a solution to this problem.
Problem Statement
You and your K-1 friends want to buy N flowers. Flower number i has
cost ci. ...
-6
votes
0answers
27 views
Stack Implementation using array [on hold]
I made this program on stack implementation using array. It is running in infinite loop without asking the user for input. Can someone point out the necessary changes required in this program.
...
-3
votes
0answers
16 views
Declaring multiple instances of a TFT screen class [closed]
Undoubtedly due to my lack of encyclopedic knowledge of C/C++, I have found myself in a quagmire while trying to initialize multiple instances of a TFT screen class. The TFT screen is the ...
6
votes
1answer
90 views
Searching in a lock-free ordered single-linked list
The code below represents a lock-free ordered single-linked list, and is a modification of the algorithm proposed in this doc.
How can I improve speed of searching (lookingup) in the list maintaining ...
0
votes
0answers
27 views
How to speed-up searching in lock-free ordered single-linked list [duplicate]
The code below represents lock-free ordered single-linked list, is a modification of algorithm proposed in this doc : http://people.csail.mit.edu/shanir/publications/Split-Ordered_Lists.pdf. To find ...
-1
votes
0answers
10 views
Developed merge sort for big arrays using pthread library in C [closed]
I was wanted in my homework to develop a parallel merge sort program according to the algorithm shown in the following figure, for any array size N=2^M (20 <= M ...
5
votes
1answer
43 views
Dynamic length binary data parsing
I am currently writing code for a UART communication in my firmware. I am getting an interrupt every byte received (meaning I don't get a chunk of data, 1 byte at a time but, in the sample below I ...
5
votes
2answers
57 views
Mandelbrot image generator 2.0
I have rewritten my C Mandelbrot set image generator, including many suggestions given in my previous question (see: Mandelbrot image generator), as well as some recomendations by a friend.
The total ...
5
votes
2answers
171 views
Showing the contents of a file
This program reads a filename from standard input and then prints its content. Please review:
...
5
votes
2answers
51 views
2D OpenGL tile atlas fragment shader
I am currently using the following glsl code to retrieve separate textures from a tile atlas:
...
1
vote
2answers
58 views
Build a time struct for current time in UTC
I'm learning about time structs. Without assigning either in code or input routines I want the current time. Please help me refactor this, if it should be.
This code just tries to make a time struct ...
4
votes
4answers
96 views
Simple calculator in C V2
My last question had a lot of views (over a 1000) so I decided to apply what I learned from the previous question and revamp the program. I learnt a lot from posting that question (functions, how to ...
10
votes
3answers
1k views
Finding the intersection of two sets of integers
I need to pass a programming exam in order to graduate but I'm having a hard time passing it because most of my programs are too slow. Can someone give me some tips on how to make my programs faster ...
3
votes
1answer
41 views
Input data from file, calculating average by a function
I want to thank you guys firstly for your previous comments and feedback. Really appreciate it. I am learning C with school at the moment, but I plan to be "fluent" in C at the end of august of this ...
15
votes
5answers
1k views
Simple calculator in C
I made a very simple calculator in C that allows the user to perform calculations like addition, subtraction, multiplication and division. This is my first C program that I've made outside of my ...
15
votes
2answers
1k views
Can I buff up your file?
Here I have a method for reading the contents of a file into a buffer and returning whether or not it is successful.
Here is what I would like reviewed:
Speed: Am I reading in the file as fast as ...
-2
votes
1answer
31 views
Reads data from file. calculates on percentage and shows a table [closed]
So this code is not yet completed. The end result has to calculate the average grade by each question. A=1 b=2 etc... and checks if the question is passed or not.
this is what I got this far.
...
-1
votes
0answers
15 views
Kth selection routine - Floyd Algorithm 489 [migrated]
I have recently come across a promising Kth selection routine that reportedly outperforms quickselect the Floyd, Rivest Select routine. This Wikipedia article provides a pseudocode version which I ...
14
votes
5answers
699 views
Mandelbrot image generator
I have written a C program to generate a PPM (Portable Pixmap) image of the Mandelbrot set. The program implements many things in C I am fairly unfamiliar with (Structures, error handling, use of new ...
3
votes
2answers
383 views
“Find the number” puzzle
A friend gave this puzzle:
Find 3 numbers (say, A B C) such that
\$ABC+ABC+ABC = CCC\$
ABC means \$((A*100) + (B*10) + C)\$. Also, these 3 digits must be distinct.
I wrote a quick code to find ...
5
votes
1answer
43 views
Optimal way to annihilate a list by removing items from the ends
I'm stuck with a contest problem.
Description:
What is the minimum number of moves to annihilate an int array where the possible moves are:
Remove both the first and last elements if they are ...
2
votes
1answer
46 views
Recreating binary counter for arbitrary length arrays
After weeks of slaving over FIPS-197, I finally have my own working C/C# implementation of AES-128 which I'm quite happy about.
The next thing I'm looking to do is implement a ...
2
votes
1answer
31 views
Generating combinations of n elements in groups of k
I've written this program that writes all the combinations (without repetition) of n elements in groups of k.
I think the code is good, but I like to know if you have some better (or faster) ...
6
votes
4answers
65 views
getline substitute that will enforce 'n' as limit of characters read
Following from a discussion with others on StackOverflow concerning the issue with getline not limiting input and happily reallocating until enough space for a ...
4
votes
0answers
36 views
Get time difference and delete file [closed]
I have a function which gets the time difference between the time written in the file name and the local time at the moment the function is called.
The file name looks like this:
...
5
votes
2answers
75 views
Project Euler #9 in C: Special Pythagorean triplet
I have finished Project Euler #9 on HackerRank:
Given \$N\$, Check if there exists any Pythagorean triplet for which \$a+b+c=N\$, \$a^2+b^2=c^2\$.
Find maximum possible value of \$abc\$ among ...
3
votes
3answers
256 views
Mockup in C of hardware implementation for multiplication of signed integers
I challenged myself to implement multiplication of signed integers using only +, -, ...
7
votes
1answer
83 views
Recovery Shell (rsh)
I wrote a shell to test my understanding of processes etc. It is not supposed to comply with POSIX or anything, just to allow people to run simple commands with simple arguments.
...
10
votes
3answers
99 views
Distance between two n-dimensional points (NASM)
I just finished writing a function that computes the distance between two n-dimensional points.
The original one was written in C and it's basically a translation of this formula:
...
6
votes
4answers
528 views
Euler #3 largest prime factor
Problem Statement
This problem is a programming version of Problem 3 from projecteuler.net
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of a given number ...
4
votes
2answers
58 views
Size improvements for cat reimplementation
I have written a reimplementation of cat that will be compliant with most scripts, and that is as small and fast as possible. Can anybody suggest some size improvements for it?
...
4
votes
2answers
67 views
A simple fork with an ugly waitpid
This is my first take on fork, exec and waitpid. I didn't quite understand why I had to use ...
2
votes
1answer
39 views
Linked List Operations in C Read Proof
I am trying to write up all the linked list basic operations (push, pop, add_at_end, pop_from_end, add_at_index, pop_from_index). This is not a school assignment, even though it may look like one. I ...
0
votes
1answer
45 views
Sorting algorithms - Relocation Counter
I want to count the total relocations for each of these sorting algorithms. From the results it seems my code is correct, but I need someone to confirm it. Is the counter variable placed in the right ...
2
votes
2answers
95 views
Dynamically sized C array
I've been working in C for a while and have decided to implement my own dynamically sized array as an exercise and to actually be used in a project.
I have also written Doxygen documentation for the ...
0
votes
1answer
82 views
Redirect standard I/O [closed]
I successfully redirect std I/O using the following functions:
Checks if input/ output file has correct format/extension:
...
2
votes
3answers
76 views
Simple and safe file reader for C
As an exercise to improve my coding ability in C, I have attempted to write a simple and safe file reader. I believe this should be portable as well to major platforms (correct me if I'm wrong). For ...
3
votes
2answers
41 views
String trim functions with destination size limitation
3 string trimming functions:
Trim whitespace from the beginning of a string.
Trim whitespace from the end of a string.
Trim whitespace from both ends of a string.
Looking to improve code ...
4
votes
4answers
315 views
Simple Word Search Game
I've created a fairly simple word search generator/solver. I'm looking to improve on picking the right algorithm to tackle problems like this, so any criticisms on my code would be greatly appreciated ...
4
votes
3answers
205 views
Caesar Cipher encryption/decryption
This program takes a command line argument of how many times you would like to encrypt plain text. After you compile the program, input a message you would like to have coded. I'm new to C and ...
5
votes
4answers
171 views
My own malloc() function in C
Is this acceptable? What is the next step to improve algorithm and make them more clear and faster?
...
3
votes
2answers
47 views
Counting occurrences of duplicate items in an array
I have to make a simple program that reads N integers from the user and counts the occurrences of duplicate items. I know that the chosen sorting algorithm has poor ...
4
votes
1answer
39 views
Remove all trailing blanks and spaces from a string
This is my solution to K&R Ex 1-18 which requires us to remove all trailing blanks and spaces from a string. I specifically wanted to use a separate function for processing the input (via ...
4
votes
1answer
61 views
Implementing pthread barrier for Mac OS/X
I have written this little thingie to fix a problem of missing pthread_barrier_t in Mac OS/X pthreads. Are there any issues with this code?
The header:
...
2
votes
1answer
50 views
Doubly Linked List implementation
At university we shortly started using C. I thought it would be a good exercise for almost everything that has to do with basic C to do a doubly linked list implementation. I tried to do it from ...
2
votes
2answers
103 views
CodeChef - Please like me
In a far away dystopian world, the measure of the quality of a person’s life is the numbers of likes he gets for an article about their life. For a person to stay alive, he has to acquire at least ...
5
votes
2answers
80 views
Performance of Median routine using min performs abysmally
I am writing a routine to calculate median using the minimum of the numbers and then changing the value of the minimum to a large value outside the range of numbers (assuming you know the nature of ...