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
1answer
23 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
0answers
25 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
35 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
34 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
630 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
110 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
63 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 ...
0
votes
0answers
16 views

Sorting an input file by a key [closed]

I'm working on some assignments for a course I have coming up in the Fall, and I was wondering what you guys think of my solution (I know it's not the best, but I want to know what I could do better): ...
4
votes
2answers
43 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
39 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
64 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
99 views

About coding style in for loop in C

Which is better? ...
8
votes
3answers
912 views
0
votes
0answers
18 views

Memory read/write access efficiency [migrated]

I've heard conflicting information from different sources, and I'm not really sure which one to believe. As such, I'll post what I understand and ask for corrections. Let's say I want to use a 2D ...
10
votes
3answers
554 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
49 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
72 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
122 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
28 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
33 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
228 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: ...
4
votes
1answer
34 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
134 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 ...
1
vote
1answer
34 views

Inline assembly correctness (especially __volatile__)

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

Arithmetic or logical right shifts

Is this code correct? Is there any major improvement I can ad in terms of number of operations? ...
8
votes
2answers
270 views

Possible optimizations for calculating squared euclidean distance

I need to do a few hundred million euclidean distance calculations every day in a Python project. Here is what I started out with: ...
5
votes
1answer
99 views

Optimizing multiplication of square matrices for full CPU utilization

Cross-post from Stack Overflow since this is very code intensive Problem I am learning about HPC and code optimization. I attempt to replicate the results in Goto's seminal matrix multiplication ...
1
vote
0answers
38 views

SSE optimisation for audio resampling

I'm learning SSE for the first time and trying to optimise some code. Using oprofile shows that the CPU usage in this function went down from 2.5% to 0.9% using the code I created. As I've only been ...
2
votes
1answer
34 views

Finding given element in minimum steps from matrix [closed]

A N*N size matrix is entered. The condition is that each element of the matrix is greater than the elements above it and left to it. Or, it can be said that all the elements on the right side and ...
1
vote
1answer
40 views

Trimming exactly two white spaces from string at O(N) [closed]

This is the optimized code I have written for removing/trimming one white space from a given string. I'm required to remove exactly two spaces from the string at the same cost of \$O(N)\$ by ...
2
votes
1answer
29 views

Multiplying a numeric string with the “vedic method”

This is vedic method multiplication. This code takes time on a very long numeric string, and I want to optimize it. I also apply recursion on multIndices (this ...
2
votes
1answer
37 views

Two squares or not two squares - constant time optimization

I have been trying to solve this problem, and after a bit of googling, I realised a \$O(\sqrt{n})\$ time complexity works fine (though the algorithm suggested is different from that I have used). My ...
1
vote
0answers
29 views

Memory leak with ARM7 core? [closed]

I'm programming ARM Cortex-M3 microcontroller. I try to implement message que. Messages are added into que inside interrupt ...
2
votes
1answer
33 views

Write int, short int or any integer value in a file in binary form using fputc

I am trying to write binary values in a file using fputc. In my case it is a short int. The file must be opened in "w" mode. ...
4
votes
3answers
151 views

Penney Game - mapping macros to strings

The SPOJ problem: Given a 40 character string representing outcomes of 40 coin tosses, find the frequency destribution of all the possible outcome triplets. So, for string like : HHHH....40 Hs ...
4
votes
3answers
90 views
3
votes
1answer
63 views

Lock-free queue with doubly linked list correctness

I need a lock-free queue which is implemented by doubly linked list. Is my code correct? Are there any errors? Are there any improvements to be made? linkedlist.h ...
11
votes
1answer
234 views

OpenGL Instanced Rendering

I have a very basic OpenGL instanced rendering setup, which is compiling and running, however it is super slow, and even though I spent days of asking and reading how to fix it, I still have no clue, ...
5
votes
4answers
235 views

Replacing strings to have a single blank

In Kernighan and Ritchie (the C programming language): Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank. I wrote the following code. ...
1
vote
1answer
58 views

Creating an array of strings from a text file

I'm try to create array of strings from a text file. I need a review from experienced programmers about my program. (MinGW gcc, Win7) ...
3
votes
1answer
50 views

Conversion from postfix to infix in C

Just over half way through in K&R, came across an exercise to convert from postfix ("reverse-Polish") notation to infix (standard) notation. Basically I'm posting here to see if there is ...
10
votes
3answers
107 views

Dynamic library to intercept oddsock hostname lookups

Just for the fun of it, I decided I would try to create sort of an intermediate DNS system for the oddsock SOCKS proxy. With this, the domain name extension .unet is statically resolved when ...
5
votes
3answers
117 views

C++ demo code for interaction with C

I want to show how to interact with C from C++ and chose a simple and small library to demonstrate. zlib's gzopen, gzwrite and ...
4
votes
1answer
54 views

Optimization of matrix determinant calculation

I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach: ...
7
votes
5answers
511 views

Treap implementation in C

I was needed a SET-like data structure written in pure C for some university class, so I've implemented a simple one - the Treap (or cartesian tree). Please check if everything is okay (actually, I'm ...
2
votes
1answer
51 views

Swapping adjacent nodes of a linked list

I just have a small question. The code I wrote works well for the problem. But is it the best way, or can we make it better? ...
3
votes
1answer
66 views

Structure and style of Enigma Machine

I took a little time and wrote the following code to produce enigma encryption. I don't normally write code in C so I would like to get feedback on the way it has been structured and any issues a ...
3
votes
0answers
57 views

Dynamic array in C

It's a dynamic array, the elements can be accessed normally and it supports any type. I believe I'm relying on undefined behavior when I treat every pointer to pointer as ...
4
votes
2answers
63 views

Are there any problems with this spun article reader?

This is a simple GTK+ program that takes a spun article as input and shows a random output every time the user clicks the "Spin" button. It supports many levels of nested spinning like: ...
1
vote
1answer
52 views

Determine how many bits are in a floating point value [closed]

I'm writing a program which determines how many bits are in a floating point value (this will be run on Unix). ...