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.

2
votes
1answer
603 views

Text-based Tic Tac Toe in C

I have programmed Tic Tac Toe in C. How can I improve the code? I have been told that system("cls") is not secure, but I don't know any other way of clearing the ...
-1
votes
1answer
71 views

C - Argparse (Argument struct)

I'm trying to make something like Python's argparse in C. I created this Argument struct and functions; is my code good so far? ...
8
votes
3answers
3k views

Integers to English words in C

As a beginner in C programming, I decided to write a function words that, given an unsigned integer n, puts the English ...
2
votes
2answers
79 views

Find a palindromic string in C

This program tests whether a string is a palindrome or not. Can there be any improvements or shortcuts that can be used in the program. You can give any type of string as input. The program finds does ...
2
votes
2answers
143 views

NxN Sudoku Solver

I have written a Sudoku solver which can solve arbitrary NxN grids via backtracking. Since I'm relativly new to C any feedback is welcome. Code: ...
-2
votes
1answer
51 views

Deleting a node in Linked list [closed]

For deleting a node in linked list I used 3 steps: 1)Finding the previous node of the node to be deleted. 2)Changing the next of the previous node.(to know what is next see my code it's fully ...
6
votes
1answer
143 views

Command line todo list manager

This is a tiny project of mine, a minimal command line todo list program that I regularly use to manage my todos. It saves todos using GitHub markdown task lists format in a plain text file. The ...
5
votes
1answer
62 views

Plain C implementation of 'Cumulative All' operation for R

I want to implement a cumulative all through R's C interface. I was able to hack something together that produces the correct results, but I have little idea what idiomatic C should look like. The ...
4
votes
1answer
175 views

Huffman Coding library implemented in C

I have written a small library for C that implements the Huffman coding algorithm as outlined in David Huffman's paper on Minimum-Redundancy Codes, and a small test program to implement it. The ...
7
votes
7answers
186 views

Calculating frequency of a note from a string

I've been working on a solution to Pset3 of CS50 Harvard course for last couple of hours and managed to finish it. Although it works as intended I'm unhappy with how clean this code is, mostly because ...
3
votes
2answers
67 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
0
votes
1answer
38 views

read line endings sequentially

This is my first C program and I'm just looking for some constructive criticism before I start trying to do more with it. Am in quite unfamiliar territory here and am uncertain if I'm releasing all my ...
7
votes
2answers
742 views

Determining whether a provided credit card number is valid according to Luhn’s algorithm

I have been working on credit problem for edx CS50 and got it working as intended. an issue I find with it is the way I have to reinitialise the cardNumber variable ...
2
votes
1answer
71 views

Sysinfo parser for a window manager status bar

The program is written mainly for the status bar in dwm (a window manager for Linux), but it can be used for any manager that takes input from the root window in X. It queries different resources in ...
2
votes
1answer
109 views

Code Vita : Chakravyuha

Problem Statement A Chakravyuha is a wheel-like formation. Pictorially it is depicted as below A Chakravyuha has a very well-defined co-ordinate system. Each point on the co-...
2
votes
0answers
58 views

CUDA kernel to compare matrix entries, weighted with a pattern

I wonder if it's possible to optimize this code in CUDA. Could I get any hints how to? Equivalent algorithm runs faster in Matlab for me, but there I'm doing matrix operations. Compution I'm not ...
3
votes
0answers
53 views

Library for managing CLI flags

I'm pretty new to C, started learning it less than a month ago, the only language I had previous experience was Javascript. Anyways, I wrote a library for dealing with CLI flags. It's not a serious ...
4
votes
1answer
516 views

Generate Christmas Tree

Problem Statement: The Christmas tree is comprised of the following Parts Stand Each Part is further comprised of Branches. Branches are comprised of Leaves. How the tree appears as a ...
3
votes
3answers
273 views

Find k-distinct partitions which contain at least two perfect squares

Problem Statement: A k-distinct-partition of a number \$n\$ is a set of \$k\$ distinct positive integers that add up to \$n\$. For example, the 3-distinct partitions of 10 are \$1+2+7\$ \$...
3
votes
1answer
94 views

Function for scanning /proc

I wrote a function, scan_ps(), for scanning /proc, to replace a combination of popen() and <...
3
votes
3answers
116 views

Safely & portably read a value into a predefined integral type of varying size like mode_t

I need to read a value from a text file and put it into a predefined type, in this particular case mode_t. This typedef can have a variety of types underlying it, ...
-1
votes
2answers
81 views

Generating parentheses using DFS

I am solving the "Generating Parentheses Given a Number" challenge. The total number of parentheses combination turns out to be Catalan Series. The following code works but I am looking for comment on ...
1
vote
2answers
47 views

Exercise 6.1 from ANSI C book - getword function

I have a following exercise from ANSI C book: Exercise 6.1. Our version of getword does not properly handle underscores, string constants, comments, or preprocessor control lines. Write a ...
0
votes
2answers
64 views

Function to copy a file using sendfile

I've just found out there is sendfile(). In the man page of sendfile(), it says: ...
1
vote
2answers
73 views

K&R Exercise 5-15: sorting with extra options

As I'm learning to program in C, I'm making my way through K&R. The goal of the exercise is to add a option to the program so that the sorting does not depend on upper or lower-case letters. ...
2
votes
2answers
75 views

Random binary digit generation and file I/O

I've recently made a program which generates a (pseudo) random binary digit (1,0) which is tied to a specific subject to learn for every day of the week. The program generates the digits the first ...
3
votes
1answer
93 views

Counting sort in C, revised

This is a revised follow-up to this question. I have implemented most of the suggestions in the accepted answer. I am interested to see what I could improve in my code and what I could do to make it ...
3
votes
2answers
155 views

Counting sort in C

EDIT: I have posted a follow-up to this question. I have implemented counting sort in C. This program takes its input as integers from command line arguments, sorts the integers with counting sort, ...
3
votes
1answer
88 views

Convert string to double and check for errors

The following program converts a string to a double, and checks for errors. It uses the strtod() function to do the conversion, and follows the example given for ...
-4
votes
1answer
44 views

Caesar cipher in C. My plaintext won't shift and the cipher text outcome is identical to it [closed]

I'm not sure what I'm doing wrong yet, but while I continue to figure it out, I'd love to get some input from others w/ experience. The goal is to cipher the plaintext using a key provided at the ...
5
votes
1answer
76 views

C application for capturing keyboard shortcuts

I'm writing an application for capturing keyboard shortcuts on Linux, but I don't have a lot of experience with C or the Linux API, so I'm wondering about problems with the code or maybe parts that ...
6
votes
2answers
658 views

Network Interface Object

I wrote a Network... thing (not really telnet); and it's pretty simple. No options, just straight I/O. It seems programs get so bloated easily. ...
4
votes
5answers
962 views

Implementing an alternative to scanf

Since almost all C functions designed to get data from stdin are bad / flawed: gets - the less said about this the better <...
1
vote
1answer
92 views

Galton Board Simulation

This program is written for Windows 7 under MinGW using gcc. I'm seeking recommendations for improving the program's portability. ...
5
votes
1answer
131 views

K&R Exercise 1-6 & 1-7: working with EOF

I'm working through K&R at the moment and I've found my first exercise that seems to be a good use for my first CodeReview post. Exercise 1-6 - Verify that the expression ...
1
vote
3answers
82 views

Given a series of characters from stdin, print their squared integer ASCII counterparts

This program in essence is extremely simple, however, it can be written in many different ways. I'm a beginner at C and I've written it in 5 different variations (mostly differing in the use of ...
2
votes
1answer
238 views

B-Tree implementation in secondary-memory/disk-memory

I will start by saying this implementation was based on the approach taken with B-Trees in the book: Introduction to Algorithms, 3rd Edition - Cormen, 2011 The implementation stores all the b-tree ...
9
votes
2answers
1k views

C code to calculate the binary period of an integer

A non-empty zero-indexed string S consisting of Q characters is given. The period of this string is the smallest positive integer P such that: \$P ≤ Q/2\$ and \$S[K] = S[K+P]\$ for \$0 ≤ K &...
5
votes
2answers
150 views

Bare-Bones implementation of printf

I made a bare-bones implementation of printf based on an exercise in Chapter 7, problem 5 of "Pointers on C" by Kenneth A. Reek. What criticism do you have of my ...
3
votes
1answer
80 views

Serializing a table for filing

I have a table in Lua, which contains two 1-dimensional arrays in which each array contains approximately 800,000 elements. I want to serialize this Lua table to file efficiently. Hence, I planned to ...
5
votes
2answers
118 views

Implementation of the `tac` command

As a C programming exercise, I implemented a minimal tac program that prints the input line by line starting from the last line. I'm looking for feedback on my ...
5
votes
4answers
606 views

Convert UTF8 string to UTF32 string in C

I'm doing some recreational programming in C (after spending some time in C++, but professionally using only PHP/JavaScript). I wrote a UTF8 to UTF32 converter and just wanted to know if I made some ...
2
votes
1answer
80 views

Function to check whether two strings are similar at given %

Since the previous question I posted here was not found as interesting as I expected, I decided to post a new one. I made a function solely for the purpose of having fun. That is, a function that ...
1
vote
1answer
45 views

Calculations to position a text box next to another object

I am implementing a program to draw a box of text next to some other drawn object (that can have any position and dimensions) and the text box should always be visible, even if the drawn object's ...
0
votes
1answer
87 views

Drawing various types of shapes [closed]

I did the following Excercise: simulate single inheritance in C. Let each "base class" contain a pointer to an array of pointers to functions (to simulate virtual functions as ...
2
votes
4answers
99 views

Calculate min, max, mean and median out of array Version 2

This question is a follow up of: Calculate min, max, mean and median out of array I took all the suggestions an reworked the code. Like the description of the excercise suggests i only use one ...
10
votes
3answers
2k views

Calculate min, max, mean and median out of array

Another C exercise: Write a function that takes an array of 'ints' as its input and finds the smallest and largest elements. It should also compute the median and mean. Use a ...
7
votes
2answers
2k views

Emulating C++ string input in C

I did the following exercise: Write a C program that does the equivalent of C++ string s; cin>>s;; that is, define an input operation that reads an ...
0
votes
0answers
80 views

Neural Network Backpropagation

My neural network is buggy somewhere. However, the reason I am posting here and not Stack Overflow is because a buggy neural network can still be trained to some degree and will compile/perform better ...
3
votes
2answers
87 views

Stack implementation in C

I have to solve an exercise from ANSI C book: Add the commands to print the top elements of the stack without popping, to duplicate it, and to swap the top two elements. Add a command to clear ...