Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [c]

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
3answers
221 views

Lookup table with fixed array

I implemented the following excercise: Implement a lookup table with operations such as find(struct table*, const char*), ...
5
votes
1answer
336 views

Codility: MaxZeroProduct - complexity issues

My solution scored 100% correctness, but 0% Performance. I just can't figure out how to minimize complexity time. Problem: Write a function: ...
5
votes
3answers
135 views

Print strings in order with dynamic arrays

I accomplished the following task to practice allocating on the heap. reading words from stdin sorting them in lexicographical order printing the sorted words To accomplish this is allocate the size ...
3
votes
2answers
115 views

Send and Receive upto 200KB over TCP/IP socket

Code reviewers, I have changed code whatever be suggested by code reviewer and I want you to give me some feedback on the basis of my new code. I have written TCP server client code to send data of ...
6
votes
2answers
96 views

Dynamically sized queue

This is my first deep dive into C, and I want to make sure that I'm not doing anything stupid. The code below creates an "Array List" of sorts, which automatically resizes itself. This code is meant ...
1
vote
0answers
83 views

System on Chip Validator

With reference to my source files, published in the git repository soc-testing I did my best effort at coding, based on 30 years of experience, so I would like to know what I did wrong with my ...
1
vote
0answers
58 views

Simple overlapped IO single threaded client

I wanted to make a single threaded network client that only uses a single connection to a server. IOCP seems like overkill but overlapped IO with event notification I think is the most performant of ...
3
votes
2answers
69 views

Find most frequent word in text file

Write a function that a receives file name of a txt file, which contains unknown number of words of max length 10 each. Print ...
0
votes
2answers
44 views

Count number of cycles in permutation

Write a function that a receives file name and an integer N as arguments, that represent a binary file which contains N integers,...
3
votes
1answer
28 views

Average readouts from multiple IR sensors with Arduino

I've written an Arduino sketch to continuously read values from multiple analog IR distance sensors, average the last 7 values and output in millimeters. Being pretty new to both Arduino and embedded ...
4
votes
3answers
134 views

Sort a linked-list with only three distinct values

I am trying to solve this problem. The problem is to sort a linked list containing only 0s, 1s and 2s by changing their links. Sort a linked list of 0s, 1s and 2s by changing links Given a linked ...
4
votes
4answers
142 views

Printing a file

The goal of this function is to print the contents of a file. Pretty much what the simple invocation of cat does. Since C is famously hard, I am looking forward to your comments. ...
6
votes
1answer
727 views

Multiple-producer, single-consumer lock-free circular queue

I'm working on a firmware on a bare-metal ARM single core processor (Cortex M4), with no RTOS. I need to add a multiple-producer, single-consumer, lockless fixed-size circular (ring) buffer to the ...
3
votes
1answer
74 views

K&R Exercise 2-6 : Inserting part of a bitset into another

"Inserting" part of a bitset into another This is Exercise 2-6 on the K&R book, 2nd edition. The reader is asked to: Write a function setbits(x,p,n,y) that returns x with the n bits that begin ...
3
votes
0answers
49 views

Print a list of disk blocks used by file(s) - Linux

This code takes a list of filenames as arguments or from stdin (or from a provided file) and dumps a list of disk blocks used by those files. An attempt is made to use the linux ...
1
vote
1answer
127 views

Implementation of counting sort

I'm trying to learn more about counting sort and I just implemented the example given in CLRS, my question is: How can I improve this code? ...
4
votes
2answers
97 views

K&R C book - exercise 3.3

I have an exercise in my ANSI C book: 3.3. Write a function expand(s1,s2) that expands shorthand notations like a-z in the ...
4
votes
2answers
58 views

My own functions for working with files

I wrote the functions for opening a file, getting a file size and getting a file contents. I would welcome any suggestions to improve my code. You might think I'm over-commenting the code. But I do ...
5
votes
2answers
53 views

Doubly Linked List implementation with C

I realized that after nearly five years of programming and one year of actual being employed as a programmer professionally that I have never actually sat down and implemented a linked list from ...
6
votes
1answer
288 views

Implementation of resizable array (Vector or ArrayList) in C

I've implemented a very simple resizable integer array in C, only including functionality to add and remove elements at various indexes. I haven't looked at using void pointers to handle any type of ...
8
votes
1answer
6k views

Read and write BMP file in C

I'm teaching myself a little C, and I've found this website. It has an exercise about manipulating a BMP file in C. I would like to know if I can make my code look more "idiomatic" or professional, ...
5
votes
2answers
101 views

Implementation of BIP-39 using C

I'm asking for anyone to review my code and provide comments here. The code has a header file but I'll show the c module here. I haven't written any C code since probably before the year 2000. I'm a ...
6
votes
2answers
183 views

Rot13 Unix Filter in C

I'm trying to brush up on some C basics (it's been ten years since I've programmed in C) and am working on a simple Rot13 program as a Unix filter. Any suggestions on how to improve it would be ...
5
votes
2answers
304 views

Send and Receive more than 64KB over TCP/IP socket

I have written TCP server client code to send data of any size (1 byte - 64KB) in a loop. The client (A) sends data to the server (B). B then sends the same data back to A. A matches the sent data to ...
2
votes
1answer
104 views

A send and receive UDP node in C

I am working on a (personal) light weight distributed project for the Rpi platform. Making it distributed requires P2P communication between the nodes, and I thought it would be a good time to learn ...
7
votes
2answers
325 views

“Ease the Array” challenge

I'm working on this challenge: Given an array of integers of size N. Assume ‘0’ as invalid number and all other as valid number. Write a program that modifies the array in such a way that if next ...
2
votes
1answer
58 views

Function that reads big files in C

I made a function that writes all the data from a hashtable to a .txt file and another to read the said data. The data comes from a this type of struct and it should be read into it when called <...
4
votes
2answers
67 views

Binary search on a uniformly distributed vector

I am trying to write a binary search using recursion in C on a sorted vector that we can assume comes from a uniform distribution between the start and end values. What I am trying to write is an ...
6
votes
3answers
349 views

Modularized Tic Tac Toe in C

I know several there have been several posts about Tic Tac Toe games previously, nonetheless I was really hoping that you may take a look at my attempt. I have tried to keep it as modularized as ...
0
votes
0answers
161 views

RGB to HSV image conversion with CUDA, with branching and branchless versions

I have created two CUDA kernels for converting a 3 channel 16-bit RGB image to a 3 channel 16-bit HSV image. The first kernel below performs the usual algorithm in a fairly straight forward manner as ...
10
votes
2answers
1k views

Hashtable Implementation - C

HashTable implementation The Specifics: It uses a simple hash function, it recieves a string and adds the ASCII values of each caracter, this can cause problems if the string is big, but for this ...
6
votes
1answer
274 views

SIMD memcpy assembler implementation

I am fairly rusty with assembler, let alone the AT&T syntax. I would appreciate it if someone with more experience could please review the following memcpy implementation. Note that this will only ...
4
votes
2answers
105 views

Interpreting strings with C-style escapes

I am working on a compiler that does a pretty heavy work on strings in order to get them correctly displayed. So far I have an algorithm that transforms a given string like (In plaintext): ...
6
votes
2answers
84 views

OpenSSL AES GCM Convenience Wrapper in C

I wrote this code for inclusion in a repository of encryption code examples. The cryptographic primitives in use are required for compatibility with the other code samples. It's been a long while ...
3
votes
0answers
121 views

Eliminating chain rules from context-free grammars

I'm writing a small C program for elimination of chain rules from a context-free grammar. My idea is to rewrite the rules of the grammar in a specific useful order: making groups of productions that ...
3
votes
0answers
97 views

HashTable with separate chaining and struct [closed]

I'm pretty new to C and I'm trying to implement a hashtable with chaining for a struct I created: HASH.h: ...
4
votes
2answers
106 views

Checking if a number is a power of 2 without loops

I made a short program which checks if a number is a power of 2 without using any loops. The idea: A number which is a power of 2 must have only one bit "1" ( ex: 8= 1000, 4=100 and so on). Suppose ...
-1
votes
1answer
722 views

Hex string to byte array in the defined order

Here is the function to convert hex string to byte array in the defined order. Any improvements? ...
0
votes
0answers
114 views

Implementation of ring buffer for reading from socket

I have implemented a simple ring buffer for providing a buffered read from a socket as shown below. I would like to get it reviewed for following things: Understand where it can be improved, if it ...
2
votes
2answers
329 views

Simple dispatcher for an embedded system

This code is something that I have used for about 3-4 simple embedded systems projects. The idea is something like this: This is non-OS based implementation, everything is done in an outer infinite ...
4
votes
2answers
91 views

Fold large input lines into smaller ones

I am working on a program that is meant to fold a large input line into smaller ones. Basic flow of the program would be as follows: User calls the program with a long string as input Program prints ...
3
votes
3answers
78 views

Swapping int with string using getchar() and putchar()

I wrote code that replaces integers from 0 to 3 with strings. I was only allowed to use getchar() and putchar(). If the input is ...
14
votes
5answers
3k views

Cryptographically Secure Password Generation in C

I am looking for ways to improve my password generation code written in C. This is in the same vein as my code in C++ and Python with many improvements. I am using ...
1
vote
2answers
74 views

Function which removes a given word from a string

Any improvements? Please review. It could be faster if I use own strstr function which searches from the end (less memory to move) but I wanted to use only the ...
2
votes
1answer
49 views

Changing a matrix by multiplying indexes of min element

I need to make the following C program: Given A (N, N) matrix (2D array). The program needs to find the min element in each column. Then it needs to multiply the row in which the element is, with the ...
6
votes
2answers
722 views

Split a char array with NUL terminators and inner delimiters

I get as an input a char array in this format: "key = value\0key = value...\0" (last pair is ended with 2 NUL terminators - one is the pair end + one is the whole ...
-1
votes
0answers
174 views

Concurrent Hash Table Implementation Using Pthreads

I am playing around with pthreads and decided to write a simple concurrent hash-table implementation. here is my code: hashTable.h ...
5
votes
3answers
150 views

Finding black cluster size distribution for square grid at different probabilities of black elements (averaged over a certain number of iterations)

Context: I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a ...
3
votes
1answer
149 views

Generic linked list

I provided an answer to a question on SO about a generic linked list. I just had the curiosity of having my code peer-reviewed as I wrote the code specifically for the answer. That is, I have not ...
2
votes
2answers
244 views

Calculate how many coins, coin values are 50, 20, 10 and 5

The code should enter an integer between 5-95 and calculate how many coins, coin values are 50, 20, 10 and 5. My concern is the CalcChange function and whether ...