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
5 views

Shortest path from U to V using at most k nodes

I'm trying to solve a problem that asks for a shortest path between two cities with at most k nodes. The first line of input has the number of test cases. On the second line 3 integers are given, ...
-3
votes
0answers
27 views
3
votes
1answer
23 views

PWM wave generation

This code takes a integer x of range [0,127] as input, returns an array of four 32-bit integers, with x bits set. I'm trying to ...
3
votes
2answers
43 views

Parsing an ini file

I have written a basic ini file parser in C. It won't support big ini files, and isn't very fast when fetching configuration values, but should be enough for small ones. I couldn't find "proper" ...
-1
votes
0answers
27 views

assembly code to c [on hold]

So I was doing the following problem, making the assembly code to C(still kind of new to assembly code) Suppose you know that when a function with prototype long decode4(long x, long y, long z) is ...
2
votes
1answer
43 views

Optimize program to test for divisibility of numbers 3.0

This is a follow up on my previous question. JS1's answer suggested that I should use a precomputed table containing all permutations of the lowest valid number for each number between 1 and MAX. It ...
-1
votes
1answer
41 views

Read Log from external memory

I log records in external memory. Every record takes \$2\$ bytes. Now I need to read \$N\$ last records in chunks of \$18\$ bytes, so I did something like this. ...
-2
votes
1answer
26 views

Finding the smallest prime number greater than a user input [on hold]

As it says in the title, I am trying to find the smallest prime number greater than my input, 'input.' I have to use the following guidelines when creating my code... You program should implement ...
2
votes
0answers
41 views

Reverse all lines in a file - valgrind error in free call + error checking style [on hold]

The script below should open a file, read and reverse every line, then overwrite the source file. ...
3
votes
1answer
58 views

Testing for divisibility of numbers - follow-up

(Here is the follow up question) I had another go at trying to speed up my program described in my previous question. JS1's answer was particulary helpful and now my code is only about 20% slower ...
1
vote
1answer
23 views

Searching and replacing text

Simple Playlist Modifier This program is a search and replace program for text based files. The main goal of the program is to replace directory paths to music files. The idea is to have the program ...
8
votes
2answers
149 views

Simple extractor for Quake-2 PAK archives

I was fiddling with the source code of Quake-2 today and at some point wanted to extract files from the .pak archives used by the game. Since I couldn't find any ...
3
votes
1answer
91 views

Allocating matrices for in-place modification

This code seems to be working. I am allocating matrices on the stack and passing them to functions to modify in place. Is this a standard practice, or am I doing it wrong? Header: ...
2
votes
1answer
20 views

Server that accepts HTML and PHP requests

For the Harvard cs50x MOOC I have completed an assignment in which a C server framework that functions like a barebones apache server is provided, to be finished by the student. The below code will ...
4
votes
2answers
52 views

Implementing N-ary trees in C

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an ...
2
votes
2answers
76 views

Program to test for divisibility of numbers

(EDIT: here is the follow up qusetion) Using this program to test for the smallest number where its permutations or itself is divisible by 10 or less numbers is twice as slow as the fastest program I ...
3
votes
1answer
45 views

Data Structures in C (Single Linked List) - Follow-up

This is a follow-up from my previous question! I cleaned up the code and added all the notes from the answers. I have also updated the code on github LinkedList.h ...
0
votes
2answers
42 views

Program to calculate smallest number with permutations divisible by a set of numbers

(EDIT: here is the follow up question) I have written a small program in C to calculate the smallest number where any of its permutations or the number itself is divisible by a set of given numbers. ...
3
votes
2answers
51 views

Low level string manipulation functions in C

I'm working with a legacy program that does a bunch of markup manipulation, some of it higher-level and specific to the proprietary markup, some of it lower level string stuff. I rewrote and ...
3
votes
3answers
57 views

Data Structures in C (Single Linked List)

NOTE: Added a follow-up question with the reviewed code I am trying to get back to basics with C, so I am doing some data structures in it. The following is my implementation of a Single Linked List ...
2
votes
1answer
28 views

Determine the number of factors of a large numbers efficiently

I am trying to determine the number of factors of a large number efficiently. I have written this function but how can it be improved upon? ...
3
votes
2answers
41 views

Correct 4 bytes out of 65K to match a crc32 checksum

I have a corrupted png image. I checked and the crc32 checksum of the first chunk (size ~65k) does not match with the one I get. I am sure of this. Also, I have ...
0
votes
0answers
42 views

Sharing data between C/C++ and other languages [closed]

I have an application (written in either C, C++, Fortran, or Python) which essentially works as follows: ...
3
votes
3answers
59 views

Max and Min in array using minimum comparisons

Is this the most robust and fastest way for finding the min and max out of an array without using STL functions? How can I improve it? ...
2
votes
3answers
74 views

Palindrome numbers - Project Euler Problem 4

Project Euler Problem #4: Largest palindrome product: A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. ...
2
votes
1answer
43 views

Optimizing binary search tree

How could I optimize this binary search tree? ...
1
vote
0answers
27 views

Using COM objects in plain C

In this code, I am creating a COM object to programatically access internet explorer. In order to access this object's properties and methods, I am writing wrapper functions like ...
5
votes
3answers
87 views

Tic-Tac-Toe - iterative implementation of alpha beta tree search

Does anyone have tips to improve the speed, clarity and accuracy of this non-recursive alpha-beta algorithm? It's my first program written in C. ...
5
votes
2answers
130 views

Program to replace tabs with blanks

From my C university book 'The C Programming Language' by Brain W.Kernighan and Dennis M.Ritchie. Excercise 1 - 20. Write a program detab that replaces tabs in the input with the proper number of ...
2
votes
3answers
69 views

Reverse part of a linked list

I'm learning data structures. I'm working on linked lists at the moment, and I'd like to have a strong grasp on them. Below is the last problem I solved. I'd like to know what you think of the ...
5
votes
1answer
42 views

ADT stack with a dynamic array (revision 1)

Here's the second draft of my ADT stack code which I posted here before after carrying out most of the improvements suggested there. I decided to expose a function called ...
3
votes
2answers
46 views

K&R (C): generate histogram of word-lengths

From "The C Programming Language" (K&R): Exercise 1-13. Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a ...
5
votes
4answers
111 views

ADT stack with a dynamic array

I'm starting to learn about data structures and coding in C. The stack is the simplest of all data structures so I'm trying to implement an ADT stack with dynamically allocated array in C. This ...
4
votes
2answers
180 views

Happy Birthday Program

I'm trying to teach myself C. I've managed to make this program I call HappyToYou.c (inspired by this video): ...
5
votes
1answer
84 views

Using a mutex to read from a file [closed]

I am new to C and I am trying to implement a mutex. The idea of the program is: main() will create three threads. Each thread will read one character each from ...
4
votes
3answers
41 views

Warshall's algorithm for transitive closure

I was going through this code for implementing Warshall's algorithm. I think the time complexity for this simple problem is huge because there are too many loops running here. The time complexity for ...
3
votes
1answer
41 views

OpenCL convolution performance optimization

I've implemented a two-step convolution in OpenCL running on GPUs. The convolution is applied to a series of 1480x1552 matrices. All matrices are pre-loaded and are stored in the ...
1
vote
1answer
24 views

Writing computer generated music to a wav.file in C - follow-up 2

See the previous iteration. What's new: endianness is now handled more gracefully (only one endianness check, and convertion if need be) and music is more funky. ...
6
votes
2answers
37 views

Pulling PE32 header info

Context Info I coded up a program that maps an executable file(.exe .dll mainly) to the program's memory space which allows for easier extraction of the PE header info. I extract the information by ...
13
votes
3answers
281 views

Lexer for C- in Python

I am currently taking a compilers course where we are designing a compiler for C- (which is a subset of C). Our first step was the lexer and I have written that but I believe that it is not very ...
5
votes
2answers
57 views

Python code to run a C program that calculates whether points are in the mandelbrot set

This is part of a project to explore the Mandelbrot set. The code to graphically navigate the complex plane and allow the user to adjust the colormap and number of iterations is all written in Python, ...
10
votes
4answers
117 views

ASCII art generator in C

I have written an ASCII art generator library. I was practicing data abstraction and code abstraction and I wanted to know if there is something that can be improved. File tree: ...
4
votes
0answers
73 views

Learning OpenMP+MPI: Feedback and comments on Gauss-Seidel+SOR

I am learning OpenMP+MPI hybrid programming. As an example I have chosen Gauss-Seidel+SOR. My implementation uses MPI_THREAD_FUNNELED style hybrid programming, ...
4
votes
4answers
99 views

Binary search implementation in C

...
10
votes
4answers
236 views

Writing computer generated music to a .wav file in C - follow-up

See the previous and initial iteration. See the next iteration. Now I have refactored the code according to many suggestions made in the first iteration. What's new: I attempted to deal with ...
29
votes
5answers
2k views

Writing computer generated music to a .wav file in C

See the next iteration. I wrote this simple C program for writing computer generated music to a WAV file over three years ago. I refactored it a little, but it does not look good to me. Any ...
3
votes
1answer
97 views

Re-implementing memcpy

I have written an implementation of memcpy function and I want to know how good is it and if it gets the most out of the processor capabilities or not. The reason ...
4
votes
3answers
89 views

State machine implementation

I have written a simple state machine. Comments and feedback are welcome. ...
2
votes
2answers
41 views

K&R atoi() variation

I'm currently learning C with The C Programming Language by K&R and this is my current exercise: Rewrite appropriate programs from earlier chapters and exercises with pointers instead of array ...