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.
4
votes
0answers
13 views
Processing trip route table in C
In fact, this is a group assignment for our C programming lesson, but seeking help from others is not considered cheating.
The goal of the following code is to:
Sort the data in ...
-3
votes
0answers
11 views
How do i fix the getnameinfo and library (Linux C)? [on hold]
Hi everyone who is reading this, i need a huge help on this code it needs to fixed on two things:
1-the library is not worling well for a code that i added (it is located between bars like ...
2
votes
1answer
24 views
Small Poker program rewrite
I had already put up code for review a small poker program but I have rewrote it utilizing a more appropriate data structure.
How would I compare Poker hands accordingly?
Full source repo
...
1
vote
2answers
18 views
Sorting structures lexicographically
I am swapping structure lexicographically by name.
Is there any way to improve the code when the structure entries are heavy.
Here is the code
...
-1
votes
0answers
15 views
Making my own Vigenère cipher in C [on hold]
I'm new to stack exchange so if there's any way to make my post more clear let me know. I might miss providing some general information that's usually including in a veteran's stack exchange post, but ...
3
votes
1answer
90 views
Fizzifying lines
Challenge
Given a test case print out a FizzBuzz Series.
Specifications
The first argument is a path to a file.
Each line includes a test case.
Each test case is comprised of ...
1
vote
4answers
62 views
Recursive function that reverse the words in a string
I have been working on a problem that asks me to a write recursive function that can reverse the words in a string. For example if the string is "cat is running", then the result should be "running is ...
-2
votes
0answers
5 views
Adding Reversed Numbers - ADDREV on SPOJ. Not Accepted why? [on hold]
I tried solving this problem on SPOJ, in which you reverse the digits of two numbers, add them, and print the reversed digits of the sum. (When reversing, leading zeroes in the result should be ...
3
votes
1answer
89 views
Finding the prime factors of a positive number
I have an assignment to write on the standard output the prime factors of a positive number displayed in ascending order and separated by '*'. My code works, but I need help reviewing it before I ...
8
votes
1answer
56 views
Longest lines using priority queue
Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue.
The idea is to be able to invoke the program like this:
...
6
votes
2answers
735 views
C the large print
This is the Longest lines challenge from CodeEval:
Challenge
Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order.
...
5
votes
1answer
42 views
Bottom up (iterative) mergesort in C
I have this C implementation of the bottom-up (iterative) mergesort:
mergesort.h:
...
0
votes
1answer
31 views
Parsing and executing a simple shell script
I'm writing a simple shell and want to parse and execute a simple shell script.
...
7
votes
3answers
2k views
Implementing atoi() in C
I was given a school assignment to implement atoi(). Please review my code.
...
7
votes
4answers
896 views
No more filthy words
Challenge
Given a list of words mixed with extra symbols. Write a program that will clean up the words from extra numbers and symbols.
Specifications
The first argument is a path to a file.
...
4
votes
5answers
118 views
10
votes
2answers
1k views
3
votes
0answers
66 views
CUDA program that emulates a kind of cellular automata slower on the GPU than on the CPU
I'm a very new to CUDA, so I'm still trying to understand how to make the best use of the GPU. I've ported a C algorithm to it. This algorithm works by loading the memory with an initial input, then ...
8
votes
2answers
72 views
Thread to send heartbeat UDP packets
This C code will run on an embedded machine with a Linux OS. It should create data packets (ASCII) to repeatedly be sent to a UDP server.
Just to give an overview about what functions should do:
...
1
vote
1answer
52 views
Mergesort algorithm in C
I have this mergesort implementation that has exactly the same API as qsort:
mergesort.h:
...
3
votes
3answers
99 views
Helper utilities for easier benchmarking in C
I have this tiny library for measuring the execution time in milliseconds and returning the duration plus the result:
execres.h
...
14
votes
1answer
168 views
Get Minimum of four and maximum up to a limit
Sita shortlists 4 gifts priced at r1, r2, r3 and r4
respectively. She wants to buy 3 of these gifts such that it doesn't
exceed her budget of x.
Input and Output Format:
Input ...
4
votes
4answers
610 views
C Socket Part-1
In my ongoing attempts to become a better blog writer I have some written some more code that needs reviewing.
Full Source: https://github.com/Loki-Astari/Examples/tree/master/Version1
First Article: ...
6
votes
2answers
114 views
Longest palindrome in an array
I am new to programming, and think this code could be improved upon. Any suggestions?
...
-1
votes
1answer
34 views
More error-checking
The purpose of this code is to check for errors in my code for a custom shell.
In a previous answer, they say that my code didn't have error-checking.
You need to check the result of every ...
8
votes
2answers
69 views
Hash table OOP implementation in C
To brush up my C I decided to do some OOP programming in C. I have never tested this before, but I was curious to try it since seeing an example of it a while ago. I decided to implement a simple hash ...
1
vote
1answer
36 views
Unit test with check testing framework
I have some code where the purpose is the decide if a char is between quotes in an expression. For example, awk '{print $1}' has a ...
15
votes
1answer
101 views
Arduino Snakes and Ladders
Here is a snakes and ladders game I made using an Arduino using a serial terminal, a set of addressable LED's to create a physical game board, a 7 segment display, and a piezoelectric to create sound.
...
2
votes
0answers
33 views
MPI BMP image comparison
I made a simple program in which I compare two images pixel by pixel and determine if the pictures are the same. I'm trying to adapt it to MPI, but I'm afraid that the communications are taking too ...
1
vote
0answers
85 views
Unwrapping multiple inner loops in CUDA for 4D nonlocal filter
I'm working on some sort of non-local means filtering in 4D space (x,y,z + time). The idea is to pass to GPU a chunk of large 4D array in order to process it and return a filtered 3D slice (then ...
3
votes
2answers
50 views
Extracting the longest line from standard input
I'm reading the K&R book and I'm interested in a program which finds the longest line on the input. I've written the same code as in the book, but I wanted to do it myself. I tried to write my own ...
12
votes
1answer
73 views
5
votes
2answers
76 views
Thread synchronization with mutex
This program prints odd numbers by thread1 and even numbers by thread2 sequentially. Can this code be optimized or made more ...
6
votes
2answers
91 views
Fast CSV parser
I have written a CSV parser to read in 12609000 lines of CSV data. Each line has 16 fields of both string and double type data. The following code takes about 40 seconds to parse the data. I would ...
1
vote
0answers
41 views
Cuda C Matrix Compression
I am using Cuda to learn and implement a CSR matrix compression algorithm. What can I do better relating to C's best practices?
main.c:
...
1
vote
1answer
53 views
Building a Stack with C structs
After reading the book from which this example is from I started using APIs like this
...
3
votes
2answers
60 views
Exercise 1-22 from K and R: line folding
I'm currently learning C with K&R, i'm right now in the exercise 1-22, but it's a little... hard to understand (at least for me). It says:
Write a program to "fold" long input lines into two ...
5
votes
3answers
83 views
Merging 3 sorted linked lists
I already know how to merge two linked list, but I needed to code a function that'll merge three already sorted linked lists into one.
I wrote a code and it is working fine, it takes care of null ...
2
votes
1answer
92 views
POSIX arithmetic expansion
I understand that a shell should be able to perform arithmetic expansion. My shell can do it:
$ echo $((1+2*3+4*5))
27
My solution uses the lemon parser where I ...
3
votes
1answer
44 views
Two variants of a picture database initialization routine
I wonder which of the two snippets is better? In the second one, I extracted two short subroutines.
On the one hand, extraction clearly separate the two tasks
On the other hand, it induces 6 more ...
4
votes
1answer
56 views
Allocating a contiguous block of memory for an array
I try to work with a contiguous block of memory, to create an array (2D) whose SIZE is not known at compile time (before c99) so no variable-length arrays are involved here.
I came up with the ...
0
votes
2answers
42 views
Two variants of a db_create_ressources(…) function
After reading noobs, I'm interested in possible way to improve readability of the following short snippet.
a struct pictdb_file is a small file system containing ...
7
votes
4answers
357 views
Custom user input function
The program consists of 3 files: demo.c, mylib.c and mylib.h. The code is heavily commented.
...
2
votes
1answer
49 views
Recursive spinlock for C using ASM
My history of C/ASM locks here in codereview:
Simple spinlock for C using ASM
Simple spinlock for C using ASM, revision #1 (basis for this approach. If this one fails, then so will the one below.)
...
3
votes
0answers
49 views
Time Limit Exceeded with shortest path algorithm
The problem:
SHPATH
You are given a list of cities. Each direct connection between two
cities has its transportation cost (an integer bigger than 0). The
goal is to find the paths of ...
2
votes
1answer
30 views
Simple pool of threads which calculate the sum of a given number from the main process
I have to make a program which creates a number of threads that are waiting at the beginning, then the main process creates a doubly linked list where random numbers are put and then a signal tells ...
3
votes
1answer
51 views
Testing different implementations of malloc()
Can you help me verify my test result? I'm testing different malloc() implementations with a small program that allocates gigabytes many times:
...
3
votes
3answers
93 views
Counting the number of primes in C and C++11
I found this old piece of code that I wrote while I was learning C a while back:
...
3
votes
1answer
49 views
Simple spinlock for C using ASM, revision #1
Revision #1 for Simple spinlock for C using ASM
The code:
...
5
votes
1answer
63 views
Simple spinlock for C using ASM
This is my second attempt to make simple lock using extended assembly.
See http://stackoverflow.com/questions/37241553/locks-around-memory-manipulation-via-inline-assembly/37246263
The code:
...