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
4answers
101 views

Dynamically-sized stack - follow-up 3

Follow up of - Dynamically-sized stack - follow-up 2 I've took the tips given to me, and what I did now is: Use same case type for type stack and it's functions Returning 1 if push failed due to an ...
6
votes
1answer
28 views

Lua bindings for FTGL (FreeType font rendering in OpenGL)

I wrote some Lua bindings for FTGL's C API. This works well enough, but I ended up with lots of macros, one for each Lua function signature. For example, LUD_NUMBER_NUMBER_TO_NUMBER creates a Lua ...
5
votes
4answers
129 views

Creating nodes for linked list in a while loop in C

I am trying to create nodes for a linked list in a while loop. The code works, but it is not very pretty. How would I get the same results the proper way? ...
-3
votes
0answers
23 views

Sharing the common code across two .c files [closed]

e1.c #include<stdio.h> #include "common.h" int main(){ printf("The add is : %d ",add(2,2,1)); return 0; } e2.c ...
6
votes
1answer
54 views

Dynamically-sized stack - follow-up 2

Follow up of - Dynamically-sized stack - follow up I've took the tips given to me, and what I did now is: changing the function names to have a prefix making the ...
4
votes
2answers
90 views

Translating warning codes as messages to be printed

I am writing an X application with Xlib in C, and this code is for error handling and error printing. How to make it simpler and clearer without using a large amount of ...
4
votes
2answers
115 views

Dynamically-sized stack - follow up

Follow up of - Which is a better implementation of a stack data structure (based on an array)? Please review my stack implementation from before. I've made it dynamically sized if needed and made a ...
2
votes
1answer
56 views
7
votes
3answers
481 views

Three functions for computing simple arithmetic

Here is my code where I have 3 functions that do simple arithmetic: ...
2
votes
1answer
39 views

Sorting an int[] array using insertion sort algorithm - follow-up

Previous questions: Is my implementation of insertion sort is correct? Sorting an int[] array with an Insertion Sort I'm currently learning about different sorting algorithms and after reading on ...
5
votes
1answer
50 views

Sorting an int[] array with an Insertion Sort

I'm currently learning about different sorting algorithms and after reading on the concept of the insertion sort of how it's done I've tried to implement it by myself before seeing how it was ...
2
votes
1answer
40 views

Is my implementation of insertion sort is correct? [closed]

I'm currently learning about different sorting algorithms and after reading on the concept of the insertion sort of how it's done I've tried to implement it by myself before seeing how it was ...
3
votes
2answers
62 views

Merge sorting linked lists

This works as expected and I want to get this code reviewed so that I can improve my coding ability. I am concerned about readability and the quality of the code ...
2
votes
2answers
56 views

Comparing two bubble sort algorithms

I'm learning C and I've got to a point learning about different sorting algorithms. Before seeing how it was done, I wanted to try doing it myself based on what I read on how it's working. ...
11
votes
0answers
45 views

Tiny Lua library to get char pointer from string

Background I'm using Lua with luaglut to do some OpenGL stuff. The luaglut API is almost identical to the gl/glut C APIs. Sometimes, gl functions want a pointer to some data, for example: ...
10
votes
4answers
457 views

Prime Factorization

I'm doing an Objective-C project and I need to do some prime factorization and so I came up with the following algorithm which is 99% C, except for the array part which was easiest to implement in ...
7
votes
4answers
116 views

Simple compression algorithm

An implementation of a simple compression algorithm that's featured in a programming practice book. My goals: Robust: All error conditions must be handled properly. The specification indicated in ...
5
votes
3answers
63 views

Bubble sorting in C

I've been into algorithms lately, so I wanted to apply a simple algorithm using a language of my choice, which was C in this case. I've implemented the bubblesort algorithm (for strings) in a simple ...
2
votes
0answers
19 views

POSIX: Synchronous event library

I have implemented a small library that handles synchronous events with POSIX compliant threads. I oriented me on the already existing POSIX thread API. Here are the files I created: ...
0
votes
1answer
37 views

Possible memory issue in linked list program [closed]

I am trying to write a program which will count the occurrence of words in a paragraph. The logic I am following : I am using a linked list for the purpose. And I am searching sequentially - if new ...
9
votes
3answers
436 views

Checking for palindromes using dynamic memory allocation

This is a homework assignment, but it's already done and it's not for a grade; it's meant as a refresher for the rest of the course. I've never done anything with dynamic memory allocation in C ...
3
votes
1answer
29 views

Iterative Flood Fill implementation in C [closed]

I am trying to implement an iterative version of flood fill in C: ...
3
votes
0answers
45 views

Synchronous events library

I have implemented a small library that handles synchronous events with POSIX compliant threads. I oriented me on the already existing POSIX thread API. Here are the files I created: ...
3
votes
2answers
90 views

Game of Life generation procession algorithm

I've tried to make Game of Life in console and this is the algorithm I used to generate new generation: ...
10
votes
2answers
311 views

Minimalistic rmdir

In my eyes most of the GNU stuff is bloated and doesn't really fit my view of how a Linux environment should look like. I have come up with my own minimalist implementation of the GNU Coreutils, but ...
5
votes
2answers
62 views

DateTime internal representation to FILETIME

Here is a routine I put together to convert SQL Server's internal DateTime representation (BINARY(8)) to a ...
6
votes
1answer
53 views

Implementation of Tower of Hanoi iterative procedure

I have been working last night on implementing Tower of Hanoi without using recursion. I have found an algorithm on Wikipedia about the same topic here. I have implemented it and it's working fine ...
11
votes
6answers
486 views

Efficiency with strcpy, strcat and malloc

I'm still learning C, but I'm trying to make sure I've got a decent grasp on working with "strings" and data structures. If possible, I'd like a little input on how I'm handling this and see if it ...
5
votes
4answers
123 views

NULL-eating / elimination version of fgets() in C

I've come up with the following routine to read data from a file stream, but I don't want any NULLs in the stream to terminate the string early. This function will ...
-4
votes
2answers
80 views

“Magic Fraction” finder

A Magic Fraction for N is one that has the following properties: It is a proper fraction (the value is < 1) It cannot be reduced further (the GCD of the numerator and the denominator ...
1
vote
2answers
79 views

Using brute force to find an energy optimal path for a given amount of time

The code below implements a brute force method to find an energy optimal path for a given amount of time t_aim using recursion (the recursion function is ...
10
votes
3answers
102 views

Add color to terminal output

I have the following header included in some of my projects so that I can add a little color to the terminal output. Here is how it would be used: ...
6
votes
2answers
81 views

Diagonal gradient optimization

With the SDL library, I'm creating an SDL_Surface* at w and h dimensions. ...
7
votes
4answers
549 views

A simple command line linear interpolator in C

I'm trying to become more familiar with C (been working through the MIT Practical Programming in C course and K&R) so decided to write a simple command-line linear interpolator. You can feed it a ...
7
votes
1answer
78 views

Queens placement

The code below is intended to be a learning material for high school intermediate programming class, as an introduction to recursion and backtracking. I was thinking of rook placement and found it too ...
-1
votes
1answer
2k views

Stone Game One Four [closed]

Alice and Bob are playing a game called "Stone Game". Stone game is a two-player game. Let N be the total number of stones. In each turn, a player can remove either one stone or four stones. The ...
2
votes
1answer
51 views

Find the nearest (small) number x where x can be represented by sum of cubes

I recently came across a problem where a number \$x\$ is given and I have to find \$y\$: \$y < x > 1\$ \$y\$ can be expressed as \$a^3 + b^3\$ (more than one combination) Example: If 4105 ...
8
votes
1answer
343 views

Project Euler #2

Problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
19
votes
4answers
2k views

Project Euler #1

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 1000. My ...
8
votes
2answers
109 views

Reasonable way to implement “safe” math operations using _Generic?

I've been thinking about a way to make it easier to safely use math operations with C's basic datatypes (e.g. using the CERT C coding standard). So far, I've come up with something like this: ...
19
votes
5answers
2k views

Aliens at the train

I solved this problem on SPOJ: The aliens have arrived to Earth and everything is in harmony, the two races can live together. However, one specific Female Alien does not want to see humans ...
10
votes
5answers
873 views

Caesar cipher cracker

How can I refactor this with less code? This is homework and is cracking a Caesar cipher-text using frequency distribution. I have completed the assignment but would like it to be cleaner. ...
6
votes
2answers
315 views

Project Euler #8: Maximum product of 13 consecutive digits

I've solved problem #8 in Project Euler, which asks to find the 13 consecutive digits with the greatest product from a particular 1000-digit number. I would like to hear any suggestions regarding my ...
16
votes
4answers
2k views

Generating 1000 random numbers

I have got the following C code and I feel it is crazy stupid and there must be a better way to do this, but just can't think of one and have yet to learn algorithms. ...
12
votes
7answers
3k views

Is this a fast implementation of reversing a string?

I thought of this algorithm today. It seems fast, but how can I know? ...
3
votes
2answers
131 views

Shuffling array elements in C

This is an answer to this problem. Basically, given an array, swap the given number of elements in the array. The solution that came to my mind: since we always swap at least two elements, pick two ...
0
votes
3answers
24 views

Determining if integers are sorted

I have this task to find whether 5 integers are ordered from the smallest to the largest or not. Depending on the results, the program output should be "yes" or "no". No loops or arrays supposed to ...
3
votes
2answers
92 views

List primes within an interval

I'm trying to solve the SPOJ primes problem: Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! ...
3
votes
5answers
354 views

Loading dictionary using trie in C very slow with large data set

The code below works for very small dictionary files I used to test (two words). However when I run this using a more typical dictionary file, my machine slows to the point of near crash. I would ...
0
votes
1answer
50 views

Multiple assignment operations in one statement [closed]

As I was writing a pretty straightforward loop to map the boundaries of a box, I found that I was doing this a lot: ...