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

3
votes
2answers
135 views

“Find the number” puzzle

A friend gave this puzzle: Find 3 numbers (say, A B C) such that \$ABC+ABC+ABC = CCC\$ ABC means \$((A*100) + (B*10) + C)\$. Also, these 3 digits must be distinct. I wrote a quick code to find ...
5
votes
1answer
37 views

Optimal way to annihilate a list by removing items from the ends

I'm stuck with a contest problem. Description: What is the minimum number of moves to annihilate an int array where the possible moves are: Remove both the first and last elements if they are ...
-1
votes
0answers
22 views

Finding prime numbers in the range (m,n) [on hold]

Problem : Find all prime numbers in the range (m,n). Input : No. of Test cases, m, n. Eg. 2 1 10 3 5 Output : Primes (m,n) Eg. 2 3 5 7 3 5 Here is my code : ...
2
votes
1answer
40 views

Recreating binary counter for arbitrary length arrays

After weeks of slaving over FIPS-197, I finally have my own working C/C# implementation of AES-128 which I'm quite happy about. The next thing I'm looking to do is implement a ...
2
votes
1answer
29 views

Generating combinations of n elements in groups of k

I've written this program that writes all the combinations (without repetition) of n elements in groups of k. I think the code is good, but I like to know if you have some better (or faster) ...
6
votes
4answers
57 views

getline substitute that will enforce 'n' as limit of characters read

Following from a discussion with others on StackOverflow concerning the issue with getline not limiting input and happily reallocating until enough space for a ...
4
votes
0answers
36 views

Get time difference and delete file [on hold]

I have a function which gets the time difference between the time written in the file name and the local time at the moment the function is called. The file name looks like this: ...
5
votes
2answers
70 views

Project Euler #9 in C: Special Pythagorean triplet

I have finished Project Euler #9 on HackerRank: Given \$N\$, Check if there exists any Pythagorean triplet for which \$a+b+c=N\$, \$a^2+b^2=c^2\$. Find maximum possible value of \$abc\$ among ...
-1
votes
0answers
30 views

dynamic array which contains dynamic array c++ [on hold]

I've stuck in a C++ code with Access Violation Error. Let me explain some of my related code. I have two structures related with each other by "item". And second struct has an dynamic array. ...
3
votes
3answers
234 views

Mockup in C of hardware implementation for multiplication of signed integers

I challenged myself to implement multiplication of signed integers using only +, -, ...
-1
votes
0answers
23 views

move the last line of a file into the top in C [closed]

I have created succesfully a file in C where I have encrypted some data. At the end of the file, I have 8 bytes that I use for identification of the file. However, I need to move these 8 bytes to the ...
7
votes
1answer
76 views

Recovery Shell (rsh)

I wrote a shell to test my understanding of processes etc. It is not supposed to comply with POSIX or anything, just to allow people to run simple commands with simple arguments. ...
10
votes
3answers
86 views

Distance between two n-dimensional points (NASM)

I just finished writing a function that computes the distance between two n-dimensional points. The original one was written in C and it's basically a translation of this formula: ...
6
votes
4answers
510 views

Euler #3 largest prime factor

Problem Statement This problem is a programming version of Problem 3 from projecteuler.net The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of a given number ...
4
votes
2answers
53 views

Size improvements for cat reimplementation

I have written a reimplementation of cat that will be compliant with most scripts, and that is as small and fast as possible. Can anybody suggest some size improvements for it? ...
4
votes
2answers
59 views

A simple fork with an ugly waitpid

This is my first take on fork, exec and waitpid. I didn't quite understand why I had to use ...
2
votes
1answer
37 views

Linked List Operations in C Read Proof

I am trying to write up all the linked list basic operations (push, pop, add_at_end, pop_from_end, add_at_index, pop_from_index). This is not a school assignment, even though it may look like one. I ...
0
votes
1answer
42 views

Sorting algorithms - Relocation Counter

I want to count the total relocations for each of these sorting algorithms. From the results it seems my code is correct, but I need someone to confirm it. Is the counter variable placed in the right ...
2
votes
2answers
92 views

Dynamically sized C array

I've been working in C for a while and have decided to implement my own dynamically sized array as an exercise and to actually be used in a project. I have also written Doxygen documentation for the ...
0
votes
1answer
79 views

Redirect standard I/O [closed]

I successfully redirect std I/O using the following functions: Checks if input/ output file has correct format/extension: ...
2
votes
3answers
76 views

Simple and safe file reader for C

As an exercise to improve my coding ability in C, I have attempted to write a simple and safe file reader. I believe this should be portable as well to major platforms (correct me if I'm wrong). For ...
3
votes
2answers
40 views

String trim functions with destination size limitation

3 string trimming functions: Trim whitespace from the beginning of a string. Trim whitespace from the end of a string. Trim whitespace from both ends of a string. Looking to improve code ...
4
votes
4answers
298 views

Simple Word Search Game

I've created a fairly simple word search generator/solver. I'm looking to improve on picking the right algorithm to tackle problems like this, so any criticisms on my code would be greatly appreciated ...
4
votes
3answers
195 views

Caesar Cipher encryption/decryption

This program takes a command line argument of how many times you would like to encrypt plain text. After you compile the program, input a message you would like to have coded. I'm new to C and ...
5
votes
3answers
143 views

My own malloc() function in C

Is this acceptable? What is the next step to improve algorithm and make them more clear and faster? ...
3
votes
2answers
43 views

Counting occurrences of duplicate items in an array

I have to make a simple program that reads N integers from the user and counts the occurrences of duplicate items. I know that the chosen sorting algorithm has poor ...
4
votes
1answer
38 views

Remove all trailing blanks and spaces from a string

This is my solution to K&R Ex 1-18 which requires us to remove all trailing blanks and spaces from a string. I specifically wanted to use a separate function for processing the input (via ...
4
votes
1answer
49 views

Implementing pthread barrier for Mac OS/X

I have written this little thingie to fix a problem of missing pthread_barrier_t in Mac OS/X pthreads. Are there any issues with this code? The header: ...
2
votes
1answer
40 views

Doubly Linked List implementation

At university we shortly started using C. I thought it would be a good exercise for almost everything that has to do with basic C to do a doubly linked list implementation. I tried to do it from ...
2
votes
2answers
87 views

CodeChef - Please like me

In a far away dystopian world, the measure of the quality of a person’s life is the numbers of likes he gets for an article about their life. For a person to stay alive, he has to acquire at least ...
5
votes
2answers
73 views

Performance of Median routine using min performs abysmally

I am writing a routine to calculate median using the minimum of the numbers and then changing the value of the minimum to a large value outside the range of numbers (assuming you know the nature of ...
3
votes
2answers
57 views

CodeChef- Chef and Strange Formula

For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p1) + F(p2) + ... + ...
7
votes
2answers
135 views

Manage multiple file writes in C

I have a very simple C program that continuously reads from a temperature sensor and displays the temperature on two 7-segment LEDs. Reading is simple, but to display the LEDs I need to write to 14 ...
0
votes
0answers
21 views

C code to represent a dataset and a 'window' of data

I'm fairly new to C so I'm looking to see if I'm heading in the right direction. This bit of code is to define a structure which represents a dataset (in this case, a GDAL dataset and some ...
0
votes
1answer
47 views

Check if two strings are anagrams - HackerEarth

You are given two strings. You have to check if the strings are permutations of each other and output "YES" or "NO" accordingly without quotes. Input: 2 lines of input each containing a ...
0
votes
3answers
51 views

SPOJ problem - The last digit of a number to a power (follow up)

As a follow up to my post here. Please refer to the problem statement in that post. I have edited this code to make it time efficient, but doing so the size of the source file has crossed the limit ...
2
votes
0answers
37 views

Off-line minimum using disjoint sets - C

The off-line minimum problem asks us to maintain a dynamic set T of elements from the domain (1..n) under the operation INSERT and EXTRACT-MIN. We are give a sequence S of n INSERT and m ...
1
vote
1answer
47 views

SPOJ problem - The last digit of a number to a power

Here is the problem statement: Given integers \$a\$ (\$0 \le a \le 20\$) and \$b\$ (\$0 \le b \le 2,147,483,000\$), where \$a\$ and \$b\$ are not both 0, find the last digit of \$a^b\$. ...
3
votes
3answers
69 views

Generating letter combinations

It's about two months since I posted this question on CodeReview. I've been working hard to improve the code posted there and came up with the following. ...
2
votes
2answers
57 views

Inverting an image

The problem is that I am trying to modify the code to invert the image in C and optimize it to make it run faster than the original by any method I could think of. After tried to use blocking and loop ...
4
votes
3answers
69 views

Bitstream reader

I have a program which reads and analyses MPEG-TS files. I've been using gperftools to identify hotspots and optimize them, and 45% of all samples at this point are in my main bitstream reader ...
1
vote
2answers
109 views

Find the smallest number Q whose product of digits is N

How do I make this efficient? ...
5
votes
2answers
233 views

Printing the n'th prime numbers

This is an online problem. The challenge is to print the kth prime number, for each k given in the input (1 ≤ k ≤ 15000). The first line of input indicates the number of inputs on the subsequent N ...
3
votes
1answer
60 views

Exotic bitmap renderer for core drawing functions

I am very interested in inventing the best way possible for rendering bitmaps on-screen using the base drawing functions (putpixel(x, y), ...
3
votes
2answers
46 views

A trivial command line utility for trimming whitespace from lines in C - follow-up 3

The previous iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up 2 Now my code looks like: ...
6
votes
1answer
66 views

Ad hoc implementation of cruise control

I've written a small C program that has ad hoc implementation of cruise control for my Altera DE2 FPGA. It works alright but there are too many global variables. Preferably there should be no global ...
1
vote
2answers
67 views

Function to rotate bitmap image

Presenting you an implementation of the "shear and transpose" method of rotating a bitmap image. It works.. but it works slow, which is fully understandable. It is understandable due to the evident ...
8
votes
3answers
682 views

Find the next multiple of N that is a perfect square number

Given a number \$t\$, (\$1 \leq t \leq 1000\$) that represent testcases and \$t\$ numbers \$n\$ (\$1 \leq n \leq 10^9\$). Show the next multiple of \$n\$ that is a perfect square number. Example of ...
1
vote
1answer
50 views

A trivial command line utility for trimming whitespace from lines in C - follow-up 2

The previous iteration at A trivial command line utility for trimming whitespace from lines in C - follow-up Note: the next iteration at A trivial command line utility for trimming whitespace from ...
5
votes
1answer
46 views

Attempting a fluent API for creating random int arrays

I have attempted doing a fluent API for creating random int arrays, and the following is what I came up with: fluent_arrays.h: ...