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

0
votes
0answers
19 views

Optimizing TSP branch and bound algorithm in C [on hold]

I implemented this Branch and Bound algorithm below but I can't get optimal results, not even with 5 points. It just works on the right child but not on the left. ...
9
votes
1answer
50 views

Bitcoin address validator in C

Here is a Bitcoin address validator I am looking to have reviewed in C. Normally I would have the enum and function prototypes declared in a header file, but I ...
6
votes
3answers
307 views

Hierarchical k-ary tree in C without relying on RAM

I created a k-ary tree in C to be used as an easy and efficient way to organize "UML-like" data in embedded devices. The left node is at the lower logical level (a child) while the right node is at ...
8
votes
3answers
328 views

Finding the largest of a series of numbers being XORed

I'm working on solving a problem involving finding the largest of a series of numbers being XORed. This is the actual problem: Xorq has invented an encryption algorithm which uses bitwise XOR ...
8
votes
1answer
60 views

Mapping enum to function - request / response library encapsulation

I'm writing code for an embedded device - specifically, a camera. The idea is different camera manufacturers can implement the code so it properly works with their camera. Here, I'm encapsulating the ...
8
votes
3answers
153 views

Output int from string input

This takes a string input like 1,2,3,4,5, splits it using , delimiter, converts each char to int and output it in a single line ...
3
votes
1answer
37 views

Simplifying linked list “search and delete” function

The function asks the user for a value to search for, then deletes all matching values in the list. The program runs flawlessly, but I can't figure out a simple/elegant way of separating cases for ...
2
votes
1answer
41 views

Implementation involving POSIX, semaphores, and locks

I am trying to get over my fear of multithreading programming and teaching myself to code using POSIX. I wrote a small version of the consumer producer problem. I am hoping I can get some feedback if ...
1
vote
0answers
19 views

C code for hash-consing: how could its performance be increased?

I've isolated this function, cons, for hash-consing in C. It is where the bottleneck of my program is. How could its performance be improved? ...
2
votes
0answers
26 views

Deleting nodes having greater value on right side

Problem Summary: Given a singly linked list, remove all the nodes which have a greater value on right side. Example: The list 12->15->10->11->5->6->2->3->NULL should be changed to 15->11->6->3->NULL. ...
1
vote
0answers
17 views

NGON (many polygons) on SPOJ - Time Limit Exceeded

I am trying to solve NGON problem. I am using bottom up dynamic programming here. Recurrence function is: ...
3
votes
0answers
44 views

Generating prime numbers using Sieve of Eratosthenes with CUDA

I'm learning CUDA and wrote a little program which generates prime numbers using the Sieve of Eratosthenes. (I know the limitations of CUDA, specially with memory sizes and limits, but this program is ...
4
votes
2answers
67 views

Static variable representing program state accessed with multiple functions

I have this method that performs certain functions based on the state that the algorithm is currently at: ...
3
votes
1answer
39 views

SPOJ is giving TLE for this solution of ROCK

I am solving ROCK problem on SPOJ. I have used bottom up dynamic programming approach for this problem. Time complexity for this is \$O(n^3)\$. ...
4
votes
4answers
369 views
5
votes
4answers
76 views

Stack implementation using only one queue in C

We start with an empty queue. For the push operation we simply insert the value to be pushed into the queue. The pop operation needs some manipulation. When we need to pop from the stack (simulated ...
2
votes
1answer
99 views

Sum the Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. ...
0
votes
1answer
33 views

Implementing a bubble sort on a linked list [closed]

I'm using the following prototype: Data* bubble_sort(Data *list); I'm trying to implement a bubble sort given a linked list of names. Note: this returns ...
7
votes
1answer
105 views

Type-length-value (TLV) encode/decode

I wrote these methods to encode data as array of TLV objects, and also to serialize and deserialize them. Any feedback on improvements, etc. would be appreciated. Please note that I ignored ...
5
votes
1answer
72 views

Consumer-Producer Problem: POSIX Thread

I have implemented a producer consumer problem, following the resources below: Oracle doc CSEE I have used mutex_t and ...
5
votes
1answer
58 views

Spell Check and Trie implementation

I have written this code for an Edx course called CS50x (a beginner course). This problem set required me to write a program which: loaded a dictionary into some sort of data structure (I choose to ...
4
votes
0answers
178 views

How bad is it calling println() often than concatenating strings together and calling it once? [migrated]

I know output to the console is a costly operation. In the interest of code readability sometimes it is nice to call a function to output text twice, rather than having a long string of text as an ...
4
votes
1answer
33 views

Basic Reverse Polish CL Parser

K and R Exercise 5-10 Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument. For example, ...
7
votes
2answers
155 views

Can I make this simulation written in C more “C++-y”?

I am learning C++ from a C background, and I was wondering if I could convert this old C program I'd written into C++ as a personal exercise. The original C program is a simple Monte Carlo simulation ...
5
votes
3answers
129 views

Go Aaaaaaaaaaah

The problem is described in full here - Aaah!. Input The input consists of two lines. The first line is the “aaah” Jon Marius is able to say that day. The second line is the “aah” the ...
1
vote
2answers
48 views

Skiena's Programming Challenges: The Trip problem

I have the following solution for the Trip problem from Skiena's and Revilla's Programming Challenges (full problem description here). ...
4
votes
2answers
65 views

C Development Utilities Library

I have been working on a small library of development utilities for some time now, incrementally improving and expanding it as I make use of it in other projects. I feel that it is fairly mature now; ...
2
votes
1answer
37 views

Priority checker for infix-to-postfix converter

I am trying to implement an infix to postfix conversion program using stacks. I have actually have done it successfully, but I'm uncertain about the complexity of the logic that I used for the ...
1
vote
1answer
36 views

How am I supposed to write a binary tree (S-Expression) pretty printer in C?

OK, I feel like I am doing something really wrong here. I'm just trying to create a binary tree, and a pretty printer for it. My approach is looking so bad I can't even... ...
9
votes
4answers
654 views

Determine if one string occurs at the end of another

Exercise 5-4 Write the function strend(s,t), which returns one if the string t occurs at the end of the string ...
6
votes
1answer
114 views

Template system for FastCGI app in C

I'm doing a small FastCGI application in C and I've created this template system to keep the design away from the code. There's a binary tree containing all possible first characters, each node ...
4
votes
2answers
66 views

Increasing performance of OpenMP based advection equation solver for Xeon Phi

I am solving linear advection equation in order to learn parallel programming. I am running this code on Xeon Phi co processor. Below is a plot of how it scales up with increasing number of threads. I ...
4
votes
2answers
55 views

Is there a more optimal way to approach some of these bitwise functions?

I completed some bit manipulation exercises out of a textbook recently and have grasped onto some of the core ideas behind manipulating bits firmly. My main concern with making this post is for ...
1
vote
0answers
44 views

How to get my simple binary encryption app to process larger files without crashing? [closed]

I got this simple binary encryption program working, but it crashes when I try to use it on larger files. I tried it on a 15mb file and it crashed, but it works fine on smaller files. How can I get my ...
4
votes
3answers
70 views

String self-similarity

It's a string problem I have been making on Hackerrank. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out". C programs ...
-3
votes
3answers
109 views

About coding style in for loop in C

Which is better? ...
8
votes
3answers
925 views
10
votes
3answers
565 views

Counting DNA nucleotides in C

I have written code to solve the following Rosalind problem. This is my first time writing in C and I would like a review of my code, particularly in regard to correctness and performance. ...
3
votes
0answers
57 views

Validating control structures in a Ruby chess AI

I'm trying to reimplement a bit of C code (the Micromax chess algorithm) as Ruby in order to run in a Ruby environment. It's mostly done, but I'm concerned about the control structures, for a few ...
9
votes
2answers
73 views

Scalability of running commands from user input

Here is some code I have that has been extracted and shrunk down from a project of mine. ...
2
votes
2answers
131 views

Check Abecedarian word

An 'abecedarian' is a word whose letters appear in alphabetical order. Write a program which will determine whether the given word is abecedarian or not and print ...
2
votes
1answer
32 views

Optimizing string replacement program that uses recursion

I have the following string replacement program for a string of size 256: I am replacing the string "\'" with the string ' Please suggest any modifications if needed or any ...
5
votes
1answer
51 views

Microcontroller ringbuffer

I'm pretty new to microcontrollers and C in general, so I thought asking here would be a good way not to get started with bad habits. ...
6
votes
2answers
243 views

Pinging a URL with libcurl

I've asked a question about pinging a URL before, but I wanted something that was a bit shorter and still just as efficient. libcurl seemed to be the perfect answer. Here is my method: ...
5
votes
1answer
62 views

Scalability of C server implementation based on pthreads

I am wondering about the feasibility of the following basic implementation of a server and how well it would scale. I know that large-scale, distributed servers should probably be written in a ...
9
votes
4answers
147 views

Bare-bones string library

After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own. This is a simple dynamic-string library ...
2
votes
1answer
39 views

Inline assembly correctness (especially __volatile__)

Here's my inline-assembly functions, which is used my x86 32bit kernel. ...
2
votes
4answers
15 views

Find out the second highest in array

I want to find the first and second highest number in an array. I could come up with one solution, but I want to know the optimum solution to do the same. Can someone help me with some alternative ...
1
vote
2answers
9 views

Displaying data as binary in C with bitmasks

I wrote a program to display data in memory as binary and it worked. (It gave me immense sense of satisfaction and joy to see this work. I guess this happens to newbies who are just testing the ...
0
votes
4answers
61 views

Arithmetic or logical right shifts

Is this code correct? Is there any major improvement I can ad in terms of number of operations? ...