C is a medium level general purpose compiled language.
3
votes
1answer
43 views
Is the following code well written?
The following program is supposed to return the length of a 'hidden' string within each of the sentences of another string, using pointers and avoiding as much as possible the use of [] as a means to ...
3
votes
1answer
25 views
PID Controller library
I'm trying to implement a PID without floating point operations on a micro controller. I appreciate all feedback I can get.
Header file:
#ifndef BRUSHPID_H
#define BRUSHPID_H
#if defined(ARDUINO) ...
0
votes
1answer
25 views
OpenMP parallelization of a for loop with function calls
using OpenMP, is it correct to parallelize a for loop inside a function "func" as follows?
void func(REAL coeff, DATAMPOT *dmp, int a, int la, int b, int lb, REAL L)
{
int i,j,k;
REAL ...
2
votes
1answer
34 views
Quicksort using pointers
As an exercise, I've written quicksort algorithm in C using pointers. Please comment and help me find the cases where it breaks (if any).
void qsort(int *, int, int);
void swap(int *, int *);
void ...
2
votes
0answers
56 views
ways to make my program shorter?
I've made a program that goes through your download directory (or any other directory you just have to change the path) and finds the files that matches your query then asks you to rename or remove ...
1
vote
0answers
28 views
MPI_Recv MPI_Send passing dump values
I wrote a parallel program where I've one process distributing jobs to the others ,when they are available they ask for it. The main process in waiting to receive a message and directs a job to the ...
-2
votes
0answers
32 views
Need help with a piece of C code [closed]
I've made a program that goes trough your download directory (or any other directory you just have to change the path) and finds the files that maches your query then asks you to rename or remove the ...
2
votes
1answer
37 views
Designing function prototypes for a singly-linked list API in C
I am in the process of rewriting in C all the data structures that I learned about a few years ago to increase my understanding of data structures and the C language. The first one I'm doing is ...
2
votes
0answers
19 views
Creating an expanding CCSprite cluster
I am creating an "explosion" of circle sprites from the character with this code, and I was wondering if there is a more effective way to do such things, because this just seems too stupid.
(This is ...
1
vote
2answers
50 views
Time limit of a c program while calculating factorial of numbers in c
I am solving a problem on calculation of factorial and the challenge is as follows!
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1<=t<=100, ...
3
votes
1answer
96 views
Fun with probability theory. Suggestions?
I want to play around with the Powerball lotto drawing history. What other probability theories could I try or what other probability class libraries exist. The code parses the file very quickly but ...
3
votes
1answer
126 views
beginner needs your opinion to gain experience
I am new to C programming and I want to know what you think about my code: things to change, things to remove, what not to do... any comment is welcome.
This piece of code basically just asks for a ...
2
votes
1answer
59 views
using C scope syntax for code organization purposes
Would you ever use curly braces for making your code more organized and readable? for instance I could have:
- (void)methodName {
...
// action 1
{
...
}
...
}
Where ...
1
vote
1answer
62 views
Brainfuck interpreter
I erroneously posted this to code-golf, where it was not appropriate.
This is my bare-bones brainfuck interpreter in C using lots of unixisms. What improvements can I make (with respect to the ...
5
votes
2answers
404 views
Is my C style good? 100 line timer program
This code works exactly as the prompt and the code predict.
Is my style good, my implementations, or what should I change, or what? I'm trying to improve my code, and writing more of it helps... Any ...
-1
votes
0answers
22 views
my program won't open the contents of a file [closed]
Why won't my program continue after I ask for the text file? Once I run the program, for some reason I doesn't seem as if it looks for the file, nor does it output the contents of the file. what can ...
2
votes
3answers
73 views
C program arrays how to make it simpler?
I have to write a program in C that reads an array with n elements and then displays how many elements are bigger than the average of the elements of the vector. Bear with me in this long code.So ,I ...
2
votes
1answer
57 views
lightweight packet sniffer review
This is a simple packet sniffer that turns on LEDs when there's network activity. It works by picking up filters in a configuration file and listen for activity in those filters. When there's a ...
1
vote
1answer
57 views
Can this solution to Project Euler #15 be improved?
I'm not a C programmer, just wanted to make a fast solution to the problem. Here's my code:
#include <stdio.h>
#define SIZE 21 // grid size + 1 ...
3
votes
2answers
88 views
Another stack implementation (in C)
I just started learning C and the online book contained the exercise 'implement a stack'. So I did, but thought I'd put it here, because I still don't feel comfortable with pointers.
So here it is:
...
2
votes
0answers
23 views
Fast popcount on Intel Xeon Phi
I'm implementing an ultra fast popcount on Intel Xeon® Phi®, as it's a performance hotspot of various bioinformatics software.
I've implemented five pieces of codes,
#if defined(__MIC__)
#include ...
2
votes
3answers
84 views
One function two functionalities or two functions each with one functionality
Within our project we've used a lot of boolean setOutputValue(char pinNumber, boolean pinValue) kind of functions.
Within those functions we do the following (for example):
hardware_layer:
#define ...
1
vote
1answer
101 views
Sorted trie implementation in C
I wanted to store some dictionary data (key/value pairs of strings) in C, and decided to use a trie.
I found what looks like a good implementation here, along with some nice notes.
In this ...
-2
votes
1answer
30 views
! operator used with int inside if statement [closed]
I am trying to understand a bit of code, and i am not able to understand how this not operator works...
if(choice==1){
for(i=0;i<4;i++){
for(j=0;j<4;j++){
for(k=0;k<4;k++){
...
0
votes
0answers
15 views
D3D COM Object Pooling
I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe?
CComPtr<ID3D11Texture2D> create_texture(const ...
2
votes
2answers
177 views
C try/catch macros
I've created simple try/catch macros that now I'd like to promote to wider use in my projects.
I would have really liked to be able to do without global variables but I have not found any way to do ...
1
vote
1answer
84 views
Singly Linked List (strings only)
This is my attempt at constructing a singly-linked-list with basic functions. I initially tried to build the whole list as a series of nodes, but ran into problems when trying to remove or pop ...
0
votes
0answers
74 views
Hanoi Towers - need help with the code
I made an algorithm solving Hanoi Tower puzzles, for n disks and m pegs.
It uses lists as pegs, each list's element contains disks array - {0, 0, 0} means the peg is empty, {1, 2, 0} means the peg ...
0
votes
1answer
99 views
Can anyone make this code shorter IF POSSIBLE
My program has to decrypt ciphertext. It has to try all possible 26 shifts and store each in an array so that I calculate the frequencies of each array and find the highest frequency, in which that ...
0
votes
1answer
42 views
Basic Linked list
I am learning C from K.N. King and at ch-17, I covered linked list and wrote a code to add data in the ascending order in the linked list which is opposite to found in the book (In the book, it store ...
7
votes
2answers
232 views
What could I have done better?
This is my first real program, though it has gone through a few major revisions. Anyhow, I am sure that there is a lot I could have done better, cleaner or safer.
Can anyone see anything I really ...
-2
votes
1answer
60 views
whats wrong with my recursion? [closed]
I am working on trying to create a tree in a recursive fashion. I have gotten constructive feedback on my previous questions so I try once more. I dont want to use malloc, and please dont post ...
1
vote
3answers
95 views
Selection sort review. Does it look good?
I always wanted to ask this but couldn't for some reason.
I had written this chunk of code about 3 months ago when one of my teacher explained what selection sort was using flow chart. I had a basic ...
2
votes
4answers
188 views
Guess the Number Game
First program in C. I'd rather not form any bad habits now. Is there anything that looks like bad practice, or something just looks wrong? Thanks!
#include <stdio.h>
#include <stdlib.h>
...
0
votes
3answers
72 views
Review: Compare two Anagrams words in C
A simple attempt by me to test whether two words are anagrams or not. Here is the code:
#include <stdio.h>
#include <ctype.h>
#define CH_LEN 15
#define N 26
int main(void) {
char ...
2
votes
1answer
146 views
My code works - but how could I improve it?
Part 1 of 4 is complete.
I would like to know if what I have done could be improved, what would you suggest.
Please don't worry about output - that is a work in progress.
file are located here:
...
2
votes
2answers
118 views
string to integer (implement atoi)
Implement atoi to convert a string to an integer.
Requirements for atoi: The function first discards as many whitespace
characters as necessary until the first non-whitespace character is
...
1
vote
2answers
131 views
Random Sentences code review
This program use random number generator to create sentences. It prints 20 sentences randomly.
Here is the code:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include ...
3
votes
0answers
89 views
Wrote high-concurrency dictionary in C, would like peer review
Project Repository
Details to know before looking at code (look for flaws in my approach before looking for code flaws)
I have include/*.h as the headers meant to be used by consumers of the ...
1
vote
1answer
38 views
Timing/Synchronization issues with interrupt-reliant code
I've started to program a state machine on a PIC18F2550 microcontroller. In each state of my machine, there is a designated block of code that runs for a specific amount of real time, such as 20 or 30 ...
1
vote
2answers
90 views
Improving my game code
I made this simple game code. Can you please give me some advice about how can I improve it ? I thought about making the screen blue and the letters yellow can someone explain me how to do that ?
...
3
votes
3answers
111 views
Length of last word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.
If the last word does not exist, return 0.
Note: A word is ...
3
votes
1answer
39 views
Aid in making a clock code more modular
Can someone help in making this clock code more modular so I will be able to use it in other bigger projects for example: turn into a c function. Here is the code:
#include <stdio.h>
#include ...
3
votes
2answers
115 views
remove duplicates in a sorted array if duplicates are allowed at most twice
Given a sorted array, remove the duplicates in place such that each element appear at most twice and return the new length.
Do not allocate extra space for another array, you must do this in place ...
0
votes
0answers
16 views
remove duplicates in a sorted array [duplicate]
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with ...
1
vote
3answers
151 views
Possible improvements for this small C program?
I'm learning C and today I wrote a program that displays info about my hardware on ubuntu.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch, file_name[25] = ...
3
votes
3answers
248 views
Translate from C to C#
I have been working on translating some code from C to C# but since I haven't been coding in C / C++ for many years now plus I do not want to resort to the unsafe keyword. I have made an attempt and ...
4
votes
4answers
152 views
Little log engine in C
I programmed a little log engine in C I plan to use in my project and maybe some others in future. I am very novice C programmer and would like to have feedback of some experienced ones on this. It's ...
12
votes
8answers
323 views
Is there a better way to code this block of C code?
This was a homework assignment that I'm now done with - I submitted it as is. However the fact that I needed to use the same code twice bugged me... The double code is:
printf("Enter a distance in ...
2
votes
1answer
149 views
Lock free MPMC Ring buffer implementation in C
I have written a lock free MPMC FIFO in C based on a ring buffer. It uses gcc's atomic built-ins to achieve thread safety. The queue is designed to return -1 if it's full on enqueue or empty on ...


