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

5
votes
2answers
96 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
27 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
36 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 ...
0
votes
0answers
11 views

Filesystem kernel mode driver stack overflow error [on hold]

I am having an issue where my driver's stack is overflowing and causing the computer to bluescreen when I call ZwCreateFile. I am just starting to develop for the windows kernel and not really sure ...
1
vote
0answers
15 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
23 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
15 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
37 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
63 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: ...
0
votes
0answers
19 views

Segfault when trying to sort a linked list of names using a bubble sort [closed]

I am trying to sort a linked list in alphabetical order using bubble sort, but I am getting a segfault when I run the program. I can print off the names before sorting, but when I sort them and try to ...
3
votes
1answer
36 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
365 views
5
votes
4answers
72 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
92 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
89 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
69 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
54 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
32 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
143 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
121 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
45 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
63 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
651 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
113 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
54 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
42 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
69 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
107 views

About coding style in for loop in C

Which is better? ...
8
votes
3answers
920 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
562 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
54 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
128 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
44 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
237 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
59 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
145 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
35 views

Inline assembly correctness (especially __volatile__)

Here's my inline-assembly functions, which is used my x86 32bit kernel. ...
0
votes
4answers
59 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
294 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
105 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
40 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
36 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 ...