C is a medium level general purpose compiled language.

learn more… | top users | synonyms

2
votes
1answer
37 views

Color fading function

I found this old color fading function in my snippets folder and would like to implement it to one of my projects. It can be used to fade one color to another. It's a very long one-liner: D3DCOLOR ...
1
vote
1answer
24 views

Pointer casting. Correct alignment and code style

There is a function that converts region code strings (1 to 4 characters and null terminator) to 32 bit integers codes to be used in maps as keys or values. Blindly casting char* to int* is bad as it ...
3
votes
1answer
48 views

Singly-linked List Library

This is sort of a follow-up to a post I created about 10 days ago, but I have completed the implementation: Designing function prototypes for a singly-linked list API in C. As I began to work on the ...
2
votes
2answers
56 views

How is this for a “Hello World” of socket programming?

I was trying out the Beej's guide to socket Programming and wrote this. Is there anything that I am obviously doing wrong? Any potential for buffer overflows? Segmentation faults? Any possible errors ...
0
votes
1answer
26 views

implement hmac sha1 in C

I am trying out a small piece of code that would generate Hmac-sha1. I have been asked to code the hmac implementation myself using the OpenSSL libs for SHA1 calculation. After 'wiki'ing for the ...
-1
votes
0answers
21 views

recvfrom() Ubuntu socket programming [closed]

I have a client code that is supposed to perform webchat with other clients on the server. When I run this code on two different hosts at the same time, I'm able to successfully send out messages ...
3
votes
3answers
58 views

Are these memory-allocation wrapper functions kosher with all C compilers?

I have never been entirely comfortable using malloc() and free() directly. For one thing, 99% of the time that I would like to call malloc, I would prefer it to take two arguments like calloc and do ...
-2
votes
0answers
21 views

Rewriting a code segment using a loop structure in C [closed]

It is required to rewrite the following code segment in C and remove all unreachable statements. There are many different approaches depending on experience. I tried some couple of solutions. I want ...
3
votes
2answers
57 views

Dining philosophers problem

Now I know this dining philosophers problem is researched a lot and there are resources everywhere. But I wrote a simple code to solve this problem with C and then turned to Internet to see if its ...
4
votes
2answers
105 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
40 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
31 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 ...
3
votes
1answer
39 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
67 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
30 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
49 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
1answer
23 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
51 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
104 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
129 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
61 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
64 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
484 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
23 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
75 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
62 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
58 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
89 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: ...
3
votes
0answers
31 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
102 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
179 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
88 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
77 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
43 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
233 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
189 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
119 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
135 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 ? ...

1 2 3 4 5 8