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.

learn more… | top users | synonyms

4
votes
1answer
14 views

“Laser treatment” SPOJ challenge

I am trying to solve this problem on SPOJ Brazil. I'm trying to approach the problem with a series of logical conditions and my code looks like this and it works perfectly. ...
-4
votes
0answers
12 views

print all primes less than 121 within 125 bytes in c [on hold]

my code for following question is ...
2
votes
1answer
24 views

Readers-Writers problem in C

I would love some suggestions on this code of mine, pointers on overall design, code quality, optimization in terms of memory and speed. ...
3
votes
2answers
29 views

Converting from base-10 to word

The following code is used to convert a base-10 number to a base-N number, where N is a length of a given alphabet that contains characters of which a base-N number ...
1
vote
0answers
13 views

Entering base characters one-by-one for a List [on hold]

This function should prompt the user to enter bases characters (a, g, c and t) one-by-one and then insert them in the List. ...
0
votes
0answers
9 views

The following code should Blink an LED as a function of an input frequency [on hold]

I wrote a code to blink an LED using PIC 16F17889. It compiles using MPLAB X but nothing happens on my board. I set the frequency to some value to test it but the LED doesn't blink at all. I dont know ...
5
votes
2answers
136 views

Edge cases for simulated malloc function

I'm trying to simulate the malloc function in C by using mmap and having 2 linked lists to act as memory blocks. The program ...
2
votes
1answer
37 views

Array-based FIFO queue in C

I have this "generic" implementation of an array-based FIFO-queue. As I have written very little code in C, I don't have an idea what to ask, so feel free to tell anything that comes to mind. ...
-1
votes
0answers
23 views

Encoding and decoding alphabet with rand and a key [closed]

I need to encode characters read from a file using srand with a key. I also need to decode the same encoded file back to the original with the same key. I am as far as encoding it, i just can not ...
8
votes
0answers
49 views

HTML/XHTML/XML tokenization

I want to write a library to parse any valid or invalid HTML-like things. First of all, I am trying to build a lexer. Here is what I did; ...
1
vote
1answer
43 views

Minimum sum of numbers

The code reads an input with numbers and find the sum with the minimum difference of the first two big numbers. The sums are three. Is there is any way to make the code cleaner? (Note that I don't ...
5
votes
4answers
465 views

C Doubly Linked List

It works, but it seems a bit long winded. I'd like some critiquing. ...
2
votes
1answer
26 views

Printing simple histogram horizontally

I am new to programming and want to know if this is really bad code. I know my variable names may seem arbitrary but I spent some time trying to get them right. I am struggling on that. Would you do ...
2
votes
1answer
32 views

Byte-to-binary conversion function

My implementation of a binary-to-bits converting function: ...
-2
votes
0answers
30 views

Hacker earth Challenge - Number of Interest [closed]

I am facing a rather humiliating problem. There is a challenge which I have solved but when I submit the code I am getting a score of zero. But it seems to be producing correct output when I am ...
2
votes
1answer
23 views

Can I be checking that buttons are pushed in a better way?

I made a panel of buttons which run commands when pushed. In order to not have the command run on every loop if the button is held down, I am comparing the button to a previous state and only run if ...
3
votes
1answer
31 views

Reading a file into memory

Can you review below code for performance and stability considerations? It is supposed to take a filename or NULL. If it is a filename, read given file into memory. ...
3
votes
1answer
29 views

Blinking LED code at a particular frequency [closed]

I wrote a function for interacting with my PIC16F1788. The code sends pulses out the RC4 port at a specific frequency, to make ...
0
votes
1answer
40 views

Optimizing Diwali Lights problem in C

I was trying to solve the Diwali Lights challenge on HackerRank. Problem Statement On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set ...
1
vote
2answers
42 views

Optimizing the runtime of the bisection method

For those who aren't familiar with the bisection method for finding the root of a function (i.e. finding where \$f(x) = 0\$) the basic idea is: take a function \$f(x)\$ and an interval \$[a,b]\$ if ...
0
votes
1answer
20 views

Moving between two angles in a set amount of time [closed]

I need to slowly change from one angle to another angle over a certain amount of time, using the shortest path between them. I have a function that accepts four parameters — the start and end angles ...
3
votes
1answer
33 views

Dynamic array implementation

I would like to use code below for general purpose dynamic array implementation in my future code. How does it look? array.h: ...
2
votes
1answer
35 views

Implementing dirpath(3p) and fdirpath(3p) functions

I'm implementing a dirpath and fdirpath functions, which allow to retrieve path from the directory handle (or its descriptor). ...
1
vote
1answer
43 views

Data structure for inserting and replacing data in list

I have a list of key value pairs, that is used as an intermediate store for building URL parameters or JSON data. Currently this is done with a linked list: ...
1
vote
1answer
50 views

ROT13 algorithm in C

I am trying to learn C and I came across the ROT13 scrambling system used to store some passwords. Assuming the user types everything in correctly (uses 1 argument, uses a string not an int, etc.) ...
2
votes
2answers
59 views

Prime factors of a number in C

The following is code on "prime factors of a number". Any suggestions to optimize the code? It runs for a pretty long time for inputs like 35068499. I also want the code to take 10 digit numbers as ...
7
votes
1answer
44 views

Restrictive stupid shell

I'm attempting to create a replacement shell for /bin/bash, that only permits commands defined by a read only config file. These commands will be run by absolute paths, and take no arguments. I'm not ...
2
votes
1answer
42 views

HackerEarth Crazy kangaroo challenge

I want to find the lowest hop count from source to destination. The challenge, in summary: The first line contains the number of test cases T, 1 ≤ T ≤ 100000. The next T lines each contains ...
3
votes
1answer
37 views

Network byte order to host byte order

While doing a little project involving sniffing packets, I found myself programming a cross platform network to host byte order and host to network byte order, this is my first time developing a ...
4
votes
1answer
27 views

K&R Exercise 1-20: tabs to spaces

I'm learning C with K&R 2nd Ed. I've just completed the exercise 1-20 and I would know if my code is correct (i.e. answering the question) and if my style is not too bad. Or just some feebacks to ...
3
votes
2answers
45 views

Rapid color replacement for in-memory BMP

A function that relatively quick replaces one color with another, in a memory-buffered BMP. I am trying to improve the performance as much as it is possible. The previous implementation of this ...
3
votes
2answers
48 views

Functional-style linked list written in C

For my Operating Systems class, I needed a linked list data structure and didn't have one already written. During the course of thinking about how to implement a linked list again (it had been a ...
4
votes
1answer
24 views

Simple file locking wrapper command in C

A simple command that wraps another command, locking a file first. It is similar to flock, just simpler. ...
3
votes
2answers
51 views

Small library for logging to MySQL

I've thrown together a utility for my programs to log to a database, but the code looks like a mess and I don't know how to clean it up. This library is going to be used from all of my other programs ...
4
votes
0answers
93 views

malloc(), free(), realloc() using brk() and sbrk()

I recoded malloc() by using brk() and sbrk(). I just want some "reviews" to see if it is ...
3
votes
1answer
33 views

Variable to byte decaying function

A function that prints out the values of each of the bytes of a variable, which value is given from stdin. Consists of size detector and a loop. ...
7
votes
3answers
410 views

RPN calculator in C

I had to write a RPN calculator in C as one of my homework problems, but if someone could critique my code and suggest any improvements, that would be fantastic! I haven't added any overflow errors or ...
6
votes
3answers
238 views

Reading, echoing, and returning integers in an array

I was wanting some clarification on my code, as I am new to pointers in C. I am trying to return an array from a simple function just so I can understand exactly what it is that I'm doing. Here is ...
9
votes
1answer
127 views

Reading, processing and counting an array setting limits

Last weekend my teacher asked me to create code to solve a problem: Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array ...
6
votes
2answers
84 views

Gauss elimination

The gauss function takes 3 parameters: a pointer to the matrix of coefficients the number of variables a pointer to matrix of solution ...
6
votes
3answers
371 views

Harvard CS50 Problem Set 1: greedy change-making algorithm

The goal of this code is to take dollar or cents input from the user and give out minimum number of coins needed to pay that between quarters, dimes, nickels and pennies. If this code can be ...
14
votes
1answer
87 views

Coroutines in C

Please have a look at this little coroutines library ccoro: http://sam.nipl.net/code/ccoro I'd appreciate a general code and style review, and your kind comments! ...
8
votes
2answers
74 views

FizzBuzz Challenge

This bit of code is a small game to see how long you play a game of FizzBuzz without messing up. Code: The top of the code: ...
2
votes
1answer
58 views

Hash table with double hashing

I writing a hash table with double hashing. This code works ONLY with ASCII text files and finding the number of occurrences of each word in input file! Please point out mistakes and shortcomings. ...
1
vote
2answers
24 views

String appending function (location-independent)

Very useful operation that hasn't been merged into a function.. until now. This is supposed to insert a substring into a previously d.allocated source string. ...
1
vote
1answer
49 views

Makefile to build library

I'm starting with make, and I made my first makefile to build my project. I don't know if it's the best way to do it or not, so I share with you my makefile to get your opinion on it: Directory ...
1
vote
1answer
36 views

Two index computations differing in execution time

Code I have the following piece of code ...
3
votes
2answers
61 views

Print input lines longer than 80 characters

"The C Programming Language" (2nd Edition) by Kernighan and Richie has this exercise: Write a program to print all input lines that are longer than 80 characters I have written the following ...
1
vote
1answer
30 views

Read file directly - simplified

In order to read a whole file as a string using standard libraries you have to allocate memory, terminate the string, determine size of the file and size of each element. This could happen with ...
3
votes
2answers
62 views

Is this program susceptible to a buffer overflow exploit?

I use it in a number of embedded devices. It loads the query parameters from an HTTP GET/POST request and prints them to stdout in FORM_key=value format which then ...