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.
-5
votes
0answers
25 views
Weird C langage issue [on hold]
I am making a game of tictactoe. For this game two players are required... Everything seems to work. However, when I created a scorecard for both players to keep count who won how many games, if ...
1
vote
1answer
25 views
Prime factors of a number in C
The following is code on "prime factors of a number". Any suggestions to optimize the code? It runs for a pretty long time for inputs like 35068499. I also want the code to take 10 digit numbers as ...
7
votes
1answer
35 views
Restrictive stupid shell
I'm attempting to create a replacement shell for /bin/bash, that only permits commands defined by a read only config file. These commands will be run by absolute paths, and take no arguments. I'm not ...
-3
votes
1answer
51 views
HackerEarth Girlfriend's Demand Challenge
The problem description can be found Here. My program is producing outputs that match the sample test cases but when subjected to large integers the program breaks down and I can't figure out the ...
2
votes
1answer
30 views
HackerEarth Crazy kangaroo challenge
I want to find the lowest hop count from source to destination.
The challenge, in summary:
The first line contains the number of test cases T, 1 ≤ T ≤ 100000.
The next T lines each contains ...
3
votes
1answer
31 views
Network byte order to host byte order
While doing a little project involving sniffing packets, I found myself programming a cross platform network to host byte order and host to network byte order, this is my first time developing a ...
4
votes
1answer
24 views
K&R Exercise 1-20: tabs to spaces
I'm learning C with K&R 2nd Ed. I've just completed the exercise 1-20 and I would know if my code is correct (i.e. answering the question) and if my style is not too bad. Or just some feebacks to ...
-4
votes
0answers
28 views
Design C Executable and Shared Library Project [closed]
I'm designing a Linux C project which is composed by two binaries: an executable and a shared library.
I have the following project structure using Eclipse-cdt:
Main Project Executable
...
3
votes
2answers
42 views
Rapid color replacement for in-memory BMP
A function that relatively quick replaces one color with another, in a memory-buffered BMP.
I am trying to improve the performance as much as it is possible. The previous implementation of this ...
3
votes
1answer
25 views
Functional-style linked list written in C
For my Operating Systems class, I needed a linked list data structure and didn't have one already written. During the course of thinking about how to implement a linked list again (it had been a ...
4
votes
1answer
21 views
Simple file locking wrapper command in C
A simple command that wraps another command, locking a file first. It is similar to flock, just simpler.
...
3
votes
2answers
49 views
Small library for logging to MySQL
I've thrown together a utility for my programs to log to a database, but the code looks like a mess and I don't know how to clean it up. This library is going to be used from all of my other programs ...
4
votes
0answers
83 views
malloc(), free(), realloc() using brk() and sbrk()
I recoded malloc() by using brk() and sbrk(). I just want some "reviews" to see if it is ...
3
votes
1answer
33 views
Variable to byte decaying function
A function that prints out the values of each of the bytes of a variable, which value is given from stdin.
Consists of size detector and a loop.
...
7
votes
3answers
391 views
RPN calculator in C
I had to write a RPN calculator in C as one of my homework problems, but if someone could critique my code and suggest any improvements, that would be fantastic! I haven't added any overflow errors or ...
6
votes
3answers
233 views
Reading, echoing, and returning integers in an array
I was wanting some clarification on my code, as I am new to pointers in C. I am trying to return an array from a simple function just so I can understand exactly what it is that I'm doing.
Here is ...
9
votes
1answer
122 views
Reading, processing and counting an array setting limits
Last weekend my teacher asked me to create code to solve a problem:
Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array ...
6
votes
2answers
83 views
Gauss elimination
The gauss function takes 3 parameters:
a pointer to the matrix of coefficients
the number of variables
a pointer to matrix of solution
...
6
votes
3answers
343 views
Harvard CS50 Problem Set 1: greedy change-making algorithm
The goal of this code is to take dollar or cents input from the user and give out minimum number of coins needed to pay that between quarters, dimes, nickels and pennies. If this code can be ...
14
votes
1answer
80 views
Coroutines in C
Please have a look at this little coroutines library ccoro: http://sam.nipl.net/code/ccoro
I'd appreciate a general code and style review, and your kind comments!
...
8
votes
2answers
70 views
FizzBuzz Challenge
This bit of code is a small game to see how long you play a game of FizzBuzz without messing up.
Code:
The top of the code:
...
2
votes
1answer
42 views
Hash table with double hashing
I writing a hash table with double hashing. This code works ONLY with ASCII text files and finding the number of occurrences of each word in input file! Please point out mistakes and shortcomings.
...
1
vote
2answers
24 views
String appending function (location-independent)
Very useful operation that hasn't been merged into a function.. until now.
This is supposed to insert a substring into a previously d.allocated source string.
...
1
vote
1answer
47 views
Makefile to build library
I'm starting with make, and I made my first makefile to build my project. I don't know if it's the best way to do it or not, so I share with you my makefile to get your opinion on it:
Directory ...
1
vote
1answer
35 views
3
votes
2answers
54 views
Print input lines longer than 80 characters
"The C Programming Language" (2nd Edition) by Kernighan and Richie has this exercise:
Write a program to print all input lines that are longer than 80 characters
I have written the following ...
1
vote
1answer
29 views
Read file directly - simplified
In order to read a whole file as a string using standard libraries you have to allocate memory, terminate the string, determine size of the file and size of each element.
This could happen with ...
3
votes
2answers
57 views
Is this program susceptible to a buffer overflow exploit?
I use it in a number of embedded devices. It loads the query parameters from an HTTP GET/POST request and prints them to stdout in FORM_key=value format which then ...
10
votes
3answers
525 views
Initializing and printing an array using pointers and dynamic allocation in C
I have written a code for basic array creation and printing it's values in C. I would appreciate comments on how it can be improved, and the industry standards.
One issue I'm encountering is having ...
10
votes
5answers
245 views
Summing user input
A small project I recently started. The program must sum all the numbers the user input. You must first specify how many numbers there will be.
Sumaster.c
...
5
votes
4answers
54 views
C readline function
I wrote this function for my next learning project (cfg parser). What do you think about it?
...
1
vote
2answers
46 views
Quicksort algorithm
I have reimplemented the quicksort algorithms that takes a list and sorts it in non-decreasing order:
...
2
votes
1answer
67 views
Producing a pyramid of capital letters
Now I'm reading C Premier Plus by Stephen Prata and there's an exercise 4 in chapter 6 which has no solution in the book, so I can't check if I did it properly. My code works like it should, but I ...
5
votes
3answers
74 views
Ini file parser project
I would appreciate any opinions and critiques anyone has on my code.
My code allow you to read a ini file.
parser.c
...
6
votes
4answers
206 views
Readline function
I have developed a readline function in C and I want to know your opinion on it:
...
3
votes
2answers
186 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:
...
6
votes
1answer
79 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
48 views
C++ Readable serial constant range counter [closed]
What I am asking here is about code readablity.
Consider the following code:
...
5
votes
2answers
72 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 ...
1
vote
1answer
66 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
92 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
68 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
201 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
52 views
Circular Queue using Linked List
I want to create a circular queue using a 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
39 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
337 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
33 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.
...
7
votes
1answer
29 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
48 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
45 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 ...