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
0answers
14 views

C Not Iterating over array correctly [on hold]

I am trying to implement insertion sort in C, but it is not stepping through the array correctly. I'm attempting to implement the pseudocode from Cormen's Algorithms book. It looks like the first ...
5
votes
4answers
85 views

Readline function

I have developed a readline function in C and I want to know your opinion on it: ...
3
votes
2answers
172 views

Efficient way of finding perfect squares

I was trying to solve a problem which needed you to count the number of perfect square in the given range: ...
5
votes
0answers
40 views

Reading, writing, and copying files

Originally, I created a program that echoes files or strings to output. This is a modification of that same program and goes a step further. It does work (in both Linux and Windows), but I can NOT ...
1
vote
1answer
40 views

C++ Readable serial constant range counter [on hold]

What I am asking here is about code readablity. Consider the following code: ...
-1
votes
0answers
18 views

What's wrong with that vigenere code? [closed]

Ok, so I am supposed to make a programme for applying vigenere's code. The programme almost works, but it loops over each letter of my plain text as many times, as there are letters in my keyword: ...
5
votes
2answers
56 views

Mandelbrot fractal with MPI

I'm not very familiar with MPI. I've written this little piece of code to draw the Mandelbrot fractal processing each row of the image in parallel. It works but it's really slow. I've written code to ...
-3
votes
0answers
11 views
0
votes
1answer
36 views

Time limit exceeded for Sherlock and Queries Hackerrank challenge

Here is my C solution for Sherlock and Queries @ Hackerrank. Watson gives to Sherlock an array: \$A_1, A_2, ..., A_N\$. He also gives to Sherlock two other arrays: \$B_1, B_2, ..., B_M\$ and ...
4
votes
2answers
82 views

Reading separate components of 8.3 filename into proper filename in C

I need to read an archive file format which stores filenames as 8 characters for the name (null-terminated if less than 8 characters, not otherwise), immediately followed by 3 characters for the ...
3
votes
1answer
61 views

Find files with similar contents

I'm not normally a C programmer but thought I'd take a shot at making something useful. This is a C utility I wrote to judge how similar several files are using the algorithm I think ...
8
votes
3answers
172 views

Breadth-first search for clusters of pixels in a given color range

I am a beginner in programming languages, so I apologise if my code is badly formatted or doesn't make any sense. My program gets an image and a RGB color range as input and it counts how many pixels ...
2
votes
1answer
36 views

Circular Queue using Linked List

I want to create a circular queue using linked list. I also want to create many instances of that data structure (queue) without repeating the code. This is what i came up with: ...
3
votes
1answer
36 views

Returning the next node

What is considered to be a good programming practice for returning value from the function? For example, if we have a function in C named ...
4
votes
5answers
334 views

Function “between” for “Everything in One Line” library

This is a function to determine if a number is between x and y. It is part of a library of mine called EOL or "Everything in One ...
1
vote
1answer
31 views

Memory searcher function test

This is part of the project I started just now. It is a function that returns the offset address of a first occurrence of a string match into a given range of memory blocks. ...
4
votes
0answers
14 views

Managing initialization for a vector abstract data type in C

As an assignment, I was to create an \$n\$-dimensional vector type for \$n \le 20\$. This vector only has to support addition and scalar multiplication. I tried to write good code, with proper memory ...
2
votes
1answer
43 views

Is this an optimal implementation of merge sort?

I am taking an algorithm course and we are to implement merge sort that handles list of elements with even or odd number of elements and handles duplication, so I wrote this function: ...
3
votes
1answer
39 views

Hashing a struct in C

I'm trying to learn how chained hashing works, but can't get any further than this. I think hashing works, but after finishing this little program, someone told me that what I have created so far has ...
2
votes
1answer
84 views

Very basic shell on microcontroller in C - follow-up

This is a follow-up of: Very basic shell on microcontroller in C A few days back I've asked for a review on a simple shell parser in c. Based on the answers I've restructured my code to use a table ...
0
votes
1answer
24 views

Iteratively-Deepening Depth First Search (queue and non-queue)

I am aware that most 'generic' BFS algorithms that use a queue also check for uniqueness of visitation to 'speed things up' as it were, but I'm a bit unclear as to how to implement such a method as ...
4
votes
1answer
15 views

Zip / merge two linked lists together

The following code interweaves two linked lists together in three flavors: iterative, recursive top-down, and recursive bottom-up. My iterative solution feels like it can be optimized better and my ...
5
votes
2answers
87 views

Very basic shell on microcontroller in C

Objective: A lightweight shell that runs on a microcontroller (MSP430) and parses incoming data into a command and additional parameters. Requirements: Support of quoting in ...
4
votes
0answers
53 views

Simple console-based car game

Below is my code for a simple console base car game. Is this a good approach or am I missing anything? CarG.h ...
3
votes
0answers
30 views

Spiral Scanning for matrix using recursion

I have written code for scanning an N x M matrix in spiral order using a recursive function. It uses 5 parameters - including 2 extra variables: call to keep ...
5
votes
3answers
108 views

Counting letters as quickly as possible

I received a task, of taking a known text file (Linux dictionary), use threads to count the different letters in it, and present the results in an array. The code doesn't have to be pretty, elegant, ...
6
votes
3answers
631 views

Find the greatest number in an array

I created a simple program in C and I want to hear your opinions. The program reads a .txt file that contains lines of numbers. The first one has one number N and the second one has N numbers as the ...
4
votes
1answer
56 views

Circular linked list in C

Let me know if it seems right to you and if anything can be optimized. My concern is that I'm unsure if circular linked lists are supposed to have a tail. I've implemented it just using a head. Is ...
2
votes
2answers
54 views

Doubly linked list code in C

Let me know if it seems right to you and if anything can be optimized. ...
4
votes
5answers
511 views

Reversed Binary Numbers

Here is my code for "Reverse Binary Numbers" in C. Problem Your task will be to write a program for reversing numbers in binary. For instance, the binary representation of 13 is 1101, and ...
-1
votes
0answers
13 views
1
vote
1answer
29 views

Print all subsets and permutations of a string

The following code is designed to accept a string from the user that is at most 5 characters long. It will then find each possible substring of the string and print all possible permutations of each ...
2
votes
3answers
125 views

Calculate the square root of the sum of the squares of the prime factors of an input number

This question is related to another one that I have asked here. I need to find ways to improve the runtime performance of the following piece of C-code. I want to increase ...
4
votes
1answer
49 views

Random bits with a specified density (Bernoulli Trials)

I'm sure this is a fully 'solved' problem and expecting cross references but I can't find this on Google. I'm probably missing a keyword. Here is a naive function for populating a ...
3
votes
1answer
73 views

Circular queue implementation using two regions

Inspired by the "bip buffer", I coded a fixed-size circular queue that uses two regions (two pairs of begin/end pointers) to account for the wrap-around. The main goal of this design was to simplify ...
3
votes
2answers
148 views

Brute force algorithm for printing all possible alphanumeric combinations

I'm still very much a beginner, so I don't really know much about best practices or the speed of any particular C functions. You'll notice that I included a "cs50" library. This is from a MOOC I'm ...
5
votes
2answers
99 views

Get line from string function

I have asked a previous question but at the last moment I realized that the code does not work as intended as it has some small bugs. I got some ideas for improvement though, but they didn't seem to ...
-2
votes
2answers
48 views
5
votes
2answers
76 views

Implementation of a quicksort function

I am an absolute beginner to programming and am learning it using C. I have just learned function pointers and tried to implement a quicksort function using function pointers to determine the nature ...
1
vote
2answers
59 views

Speeding up Hexadoku

I have serious problem with my Hexadoku (16 x 16 , a - p) solver. I'd like to run the program in under 2 seconds but my solution solves it in 10 seconds. Native Code: ...
6
votes
2answers
80 views

Read file line-by-line with circular buffer

This isn't too complicated but I usually code in C++ instead of C. Doing memory management and IO in C always makes me feel like I'm doing everything wrong and making a mess. This is a small sample ...
4
votes
0answers
63 views

Optimization of sparse matrix multiplication for billion by billion matrices

I have to do multiplication of two billion by billion sparse matrices (on a CPU), hence any help or hints in optimizing the below given code would be extremely useful. Note: I am only showing the ...
1
vote
2answers
51 views

Sort and display input numbers

How do I decrease time, especially in sorting? Given a list of numbers, you are to sort them in non-decreasing order. Input t – the number of numbers ...
6
votes
2answers
86 views

Quaternion rotations and preparing matrices for a shader

I am implementing an OpenGL ES 2.0 renderer in c. I want to use quaternions for rotations. Please take a look at the way I am implementing the rotation math. Everything looks as expected when the ...
4
votes
1answer
148 views

Calculate the average score of groups and each student, C

I have a file containing information about the session of students. The structure of this file is: group number, student name, exams, and tests. debt() function ...
3
votes
3answers
88 views

Producer-consumer code

The idea I have in my head is this: I am not sure if I need the index variable in consumer and producer. Moreover, I want to know if it is OK like this (it ...
6
votes
1answer
65 views

Reading integers from a file and counting the length of a descending subsequence

I had a school project to solve, which I did. The basic focus of the project was to create the simplest code possible to solve it. This topic was created just to ensure if I wrote the code correctly. ...
4
votes
1answer
53 views

Downloading images from a forum

I want to improve this program so I want you to criticize the code, and tell me what else can I do, and where can I find information about what I have to do. TODO: Fix ...
4
votes
1answer
44 views

String parsing/stripping code

I am mostly interested in how the parse_string function could be improved. But any comments on my test strategy also welcome. The input is a string which can be ...