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.
3
votes
2answers
47 views
“Safe” memory management
In order to concisify the handling of a failed call to malloc, realloc, or calloc, I have ...
0
votes
0answers
36 views
Fetch value from website using cURL
I want to make a http request, get the website content and check one specific element. Currently I'm doing it with lcurl (got explanations from a tutorial). Here is an excerpt of my code:
...
4
votes
1answer
62 views
Conway's Game of Life in Win32/GDI
I've implemented Conway's Game of Life using the raw Windows API and GDI as an exercise. I'm wondering if there is room for improvement, though.
Beware, large amount of code following:
CGOL.h:
<...
-2
votes
0answers
18 views
Compiling kernel from source. error explaination. [migrated]
I am compiling an android kernel from source. But getting stuck with some error in making the object tspdrv.o and cant make out where it is generating from. ...
6
votes
2answers
330 views
Creating index to a file in C
My task was to index a file in C.
I'm getting one argument: file name. The index should contain all the words and a line list which appears in.
A few notes:
Big and small letters are the same.
A ...
3
votes
1answer
42 views
OpenGL 3 Mandelbrot Set
I've written a short program to learn about computing with drawing using OpenGL 3. To do so, I created a program to create two triangles, which form a quad, and pass all the arguments for computing ...
7
votes
2answers
91 views
Algorithm to find a path
I have implemented A* in C, and was wondering about what I could do to improve it.
My main concerns are readability, usability and last but not least performance.
My NodeList is an attempt at making ...
1
vote
1answer
47 views
Parser Combinators in OO C
In trying to understand and use the Parser Combinator concept, I've coded up as close an analogue as I could manage within the constraints of the C language.
C doesn't have first-class functions or ...
-6
votes
0answers
27 views
How to add a repeat loop in multiplication result? [closed]
What I need is to create a series of numbers from the code below.
First set value 2 for input s2.
Then multiply s1 by ...
-6
votes
0answers
21 views
Program to print histogram of length of words (please don't delete) [closed]
Ok guys, you've put my question on hold, but i'm posting it again as I haven't received an answer as to where I'm going wrong. I do know that this code is buggy, I just want to know why the code isn't ...
-2
votes
0answers
23 views
Buggy output for C histogram program in K & R [closed]
Ok so I've been attempting the exercises in the K & R book, and I've come to the histogram exercises to print the length of words in an input.
Now the code that I've written is running and is ...
5
votes
4answers
83 views
Finding students with the best grades in a given subject
We have a school assignment, in which the program is to read data of students from stdin, in the following format: LASTNAME FIRSTNAME STUDENT_ID SUBJECT AVERAGE_GRADES. The program has to print out ...
-4
votes
0answers
20 views
Program to print a histogram of the length of words in an input (BUGGY) [closed]
first time poster here
I'm trying an exercise in the K and R book to print a histogram of the length of words in an input. The code below is how far I've come. This isn't my first attempt, but it's a ...
3
votes
2answers
71 views
Efficient integer input / output (with a use case)
The task:
A set of functions used to read/write integers from/to stdin/stdout as efficiently as possible.
Rationale:
printf/...
3
votes
1answer
35 views
CS50 Pset1 Greedy, change algorithm
The purpose of the code is to calculate the least amount of coins needed to produce correct amount of change given a dollar or cent user input. I'm just starting out and appreciate any pointers in how ...
-3
votes
1answer
59 views
Forming digits on a grid by toggling 5-pixel diamonds
Context: https://www.reddit.com/r/ProgrammerHumor/comments/6ggzvz/exceptionally_late_to_the_party_here_is_my_phone/
Some time ago, /r/ProgrammerHumor was flooding with phone number inputs. In the ...
3
votes
1answer
29 views
Sorting a singly linked list with natural merge sort in C
This C program implements a so-called natural merge sort that identifies existing runs in the list and exploits them in order to sort in sub-linearithmic time whenever possible. The running time of ...
3
votes
2answers
79 views
Sum of Subset of an Array equals a given number
The exact question that I am solving is given here: Codechef - MARCHA1
Problem Statement
Basically, we have an array of n integers, say {1, 5, 6, 3, 12} where n = 5.
Then we have a given number ...
8
votes
6answers
544 views
Singly Linked List C implementation
I'm a C beginner. I'm studying and implementing some data structures. I'd like to get feedback about my style and decisions I made.
This is a Singly Linked List. I decided to keep things as simple as ...
4
votes
1answer
33 views
Lucas Lehmer Primality Test
I have coded the Lucas-Lehmer primality test following Wikipedia's description. I used the mod 2^n - 1 suggested in the article but was wondering if there were any ...
4
votes
0answers
61 views
Fast ray/triangle intersection code in C
I wonder if someone is familiar with ray/triangle intersection algorithms and can help me optimize them?
Here are my implementations of two ray/triangle intersection algorithms in C. The first is the ...
0
votes
3answers
228 views
Checking if a string is a palindrome
This is the code for checking if a string is a palindrome. The execution time, for sample cases, is 0.40358 seconds. What must be done to increase the performance?
...
-2
votes
1answer
27 views
Greedy: 1.01 adds up to 4 coins but 1.02 reaches 5 [closed]
I saw below and those are great examples to use as a guide. I tried borrowing from both do my own thing, even though it probably isn't as efficient as those. Why does input 1.01 return 4 coins but 1....
4
votes
1answer
61 views
Project Euler Problem #51 in C
Here is the problem statement for problem #51:
By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
...
4
votes
2answers
48 views
F'up: Arbitrary large unsigned integers
This is a followup question to Arbitrary large unsigned integers. The feedback was very helpful and made me redesign large portions of the code.
I changed the ...
3
votes
4answers
274 views
Find if a number is equal to the sum of its divisors
A number is perfect if it is equal to the sum of all its divisors. For example divisors of 6 are 1, 2, 3. I want to read numbers,...
3
votes
1answer
43 views
How to sort array by divisor sum faster?
I am sorting an array by divisor sum in ascending order. If two or more numbers have the same sum of divisors they have to be sorted in ascending order. The problem I have is that my version is not ...
3
votes
2answers
89 views
C program to handle information of cars and owners
This is a school assignment, it's the longest program I've wrote this far, and I feel it's a bit messy and all over the place. I will try to translate the assignment to the best I can:
We have a ...
8
votes
2answers
102 views
Arbitrary large unsigned integers
Edit: There's now a Follow-up question concerning more recent code.
From time to time, you see a question over at Stack Overflow about calculating factorials, typically asking why the result soon ...
4
votes
2answers
120 views
Decimal to binary array
Basically, this program takes a decimal number from 1 to 10, that is the index of power of 2. And turns into an array with \$2^n\$ combinations.
For example: If my decimal is 1, I'll have 2 arrays, <...
4
votes
1answer
50 views
C random walk the alphabet on a small grid
I'm teaching myself C, with an older edition of K. N. King's C Programming: A Modern Approach. I come from a Python and JavaScript background as far as programming goes, but not a strong foundation in ...
2
votes
3answers
555 views
Counting the minimum number of blocks to remove to form a triangular temple
PROBLEM STATEMENT :
You want to build a temple for snakes. The temple will be built on a
mountain range, which can be thought of as n blocks, where height of
i-th block is given by hi. The ...
7
votes
3answers
248 views
Faster solution to compute magic numbers
There are N doors with a number on each door. You have a golden key(K) and you can open with it only doors on which the numbers ...
3
votes
2answers
57 views
Solution to itoa
As some of you might know I've been working my way through the C Programming Language (2nd).
I recently finished a rough implementation of the itoa exercise (...
1
vote
1answer
57 views
Sequence of numbers which follow a rule
I have a sequence of numbers: 1, 2, 3, 5, 8, 3, 1, 4, 5, 9, 4, 3, 7, 0, 7, 7, 4,... I have to guess the rule which the sequence follow and to:
Compute the sum of ...
3
votes
1answer
52 views
4
votes
1answer
68 views
C - Client Server application
I must create a client-server application. This application must calculate the average and variance of a sample.
The client sent the number in this format: 2 3 4, where the first number mean how many ...
2
votes
0answers
102 views
Convert FoxPro/dBase DATETIME field to Win32 SYSTEMTIME struct
I'm trying to write a complete driver for Visual FoxPro's DBF format for Win32. I found that the way that fields of the DATETIME type are stored in dBase files is ...
7
votes
1answer
708 views
Singly LinkedList in C
I've finalized my (didactic) implementation of a singly LinkedList in C which resides on the Heap.
I've put efford into keeping this as simple as possible and clean - while documenting it nicely. I ...
6
votes
1answer
48 views
Statistics mode function
I will get straight to the point - I am a freshman at uni and I am currently working on my first bigger personal project - Statula is a terminal tool for data analysis which takes in dataset (as a ...
1
vote
2answers
75 views
Finding the predominant number in an array
My program has to read an array and say whether there is a predominant number or not in the array. A predominant number is the one with frequency bigger than number of elements of the array divided by ...
-2
votes
2answers
69 views
An array adding numbers to a specified sequence
I have to make a program that modifies an array like this: it takes a sequence in an array and sums up a number to each element in the sequence and repeats this many times. The array's elements are <...
3
votes
2answers
118 views
FIFO, FILO, LIFO and LILO integer stacks in C
One of my current side projects includes a stack-based interpreter written in C for a programming language I'm designing, SSBL. Since the entire language is stack-based, I needed a way to create and ...
7
votes
4answers
113 views
Viterbi algorithm implementation in C
This is an implementation of the viterbi algorithm in C, following from Durbin et. al.'s book Biological Sequence Analysis (2002). There's more info in the heading about usage and what exactle the ...
5
votes
4answers
182 views
change space to underscore in filename using C
I have written my first C program that renames spaces in filenames to underscores. I wonder if there is an easier or more efficient way:
...
3
votes
1answer
63 views
Iterating pattern (1-10 then 10-1) with only 1 loop
I want to obtain the following output:
1 2 3 4 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10
The code am running is as follows:
...
5
votes
1answer
62 views
Exercise – Synchronization between threads using `pthread_mutex_t` and `pthread_cond_t`
I have got an assignment for an OS course that consists in the use of mutex and condition variables to synchronize N threads, each involved in the search of a character in a row of a NxN matrix.
The ...
1
vote
0answers
34 views
C program to convert a sum of money to Indian Number Format
I wanted to build a C program to convert any number to Indian Currency Format. It can take inputs with negative sign, leading zeros and Decimal point + Mantissa and it will format the input to take ...
2
votes
0answers
56 views
Yet Another Linked List
I've been populating my git with some old code, and I came across this linked list I wrote about 10-12 months ago. I'm wondering just how thread safe it is and if there are any improvements I can make ...
3
votes
1answer
50 views
Find factors of a number
I am a beginner in C. I have just written this program to find the factors of a provided number \$n\$ where \$1\leq n \leq 10^9\$. However, when I input large numbers (e.g. the maximum, \$10^9\$), the ...