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

-4
votes
0answers
17 views

check why my code is not working [on hold]

I wrote this simple code that checks if 2 arrays can be re-arranged to be equal to each other, yet it's not working.. can't find the bug.. help please. ...
-1
votes
0answers
18 views

Simple stack-linkedl list calculator in C [on hold]

I'm trying to write a simple postfix calculator that reads the line and performs the calculation using a Stack. I was wondering if somebody coudl check if is struct's and push function are correnctly ...
-3
votes
0answers
19 views

Transposing matrices [on hold]

The idea is to use functions in order to transpose matrices. For some reason, C won't allow me to return the arrays themselves so I tried using pointers. I'm not very good with pointers, so this ...
4
votes
1answer
29 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 ...
7
votes
1answer
56 views

Making multiple copies of a pattern

Here's a function for making multiple copies of a block of memory in another block of memory. It handles the case when the size of the target is smaller than or not a perfect multiple of the source ...
4
votes
1answer
62 views

Logging library for C

Over the past couple of weeks I have been working on a general purpose logging library for C in my free time. At the moment I have stabilized the API and most of the features I wanted to implement ...
8
votes
1answer
58 views

Create a Christmas Tree

This function draws a Christmas tree (with an angel on top) with text (AKA, ASCII art). ...
13
votes
2answers
75 views

Playing with strings

I wanted to dust off my C skills, so I decided to write a couple string manipulation functions. I aimed for simplicity and safety. Performance was not a concern. Please be a thorough as you like. C ...
5
votes
0answers
36 views

Inferring Memory Alignment

The following code is intended to infer the alignment of double. My questions include: Is there a better to do this? Either by refining the code or using an ...
2
votes
0answers
16 views

Putting rows of ascending digits and eliminate rows of other digits, leaving other symbols intact

For example, sequence "aasdf123456785fg87" will be transformed into "aasdf12345678fg", using getchar and putchar and then using ...
0
votes
0answers
36 views

A different implementation of Heap Sort

The following implementation is a bit different form the standard implementations I have read. Is it correct? ...
4
votes
2answers
121 views

Filter leading zeroes from numbers using only character operations for input and output

Problem: to eliminate initial zeroes from numbers besides those followed by '.' or alone. For example if we input a-000123+bc+0000.0008-0000+0001.07 , we will get ...
1
vote
1answer
39 views

Mapping yielding lots of warnings in use

Recently, I wrote a C header file that defines a new type called HashMap that allows for the storage of key/value pairs. I am just learning about the wonders of ...
2
votes
2answers
74 views

Finding the size of a file

I recently learned that sometimes, when running code, the compiler(or whatever it is) ignores when there isn't enough memory for say, a string, and interacts with the string normally. Yes, I know ...
3
votes
2answers
79 views

Tic Tac Toe in C

I implemented a version of the popular Tic Tac Toe game. It currently only supports two-player mode, but I'm planning to add artificial intelligence for user vs computer mode (which I don't know how, ...
1
vote
0answers
32 views

“Restaurant” HackerRank challenge in C

I don't write C all that often, so things to look for would be memory leaks and such. I also recognize that I'm not validating the user input as well as I could - I could use some feedback on how I ...
-2
votes
0answers
23 views

replace rows of n(n>=2) '*' symbols with n/2 '+' symbols [closed]

Only using getchar() and putchar(). For example having entered "asf****f*d" you get "asf++f*d". The signal of the input's end is ...
5
votes
4answers
69 views

Summing Divisors

Definition: A proper divisor of a natural number is the divisor that is strictly less than the number. e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 ...
3
votes
2answers
28 views

Cut float numbers in a stream (putchar, getchar) and in a string

For example, the following row: "a+12.3456-b-0.456789+1.3-45678" will be transformed into "a+12.34-b-0.45+1.3-45678" That is, we need to cut out the figures after the point from the third figure. ...
6
votes
2answers
145 views

Printing twin primes less than a given natural number n

I have two programs doing this task correctly, but at first I'm not sure if the code is correct (I mean absence of not efficient and superfluous pieces of the code). Then, I can't choose which one is ...
8
votes
2answers
85 views

The benefits of sentry in a linked list

I'm trying to put together a little tutorial to demonstrate the benefits of using a sentry node when creating a linked list. Target audience is novices that already tried to make a linked list. Any ...
10
votes
2answers
97 views

A program that reads input until end-of-file and echoes it to the display

It echoes files or strings to output, never both at once. It does work (in both Linux and Windows), but I can NOT guarantee that it is bug free. It works much like echo, but it works with files as ...
3
votes
3answers
262 views

Creating a string from command line arguments

I am fairly new to C and am just overcoming my fear of pointers and segmentation faults. C is a strange language to me because I come from more object oriented languages like JavaScript and Java. ...
3
votes
1answer
33 views

AVL tree implementation in C

I have an assignment. I need to write an AVL tree. This is what I have written so far. It works on all of my tests, but suddenly fails in checking system with TL(time limit exceeded). Personally I ...
4
votes
2answers
59 views

Function to grab stdin, stdout, stderr of a child process

I've managed to create a function to pipe the stdin, stdout and stderr of a child process ...
2
votes
1answer
60 views

Implementing a simple queue in C

I am learning C and I have some trouble with pointers. I decided to create a queue to practice a bit. The program works as intended, however I want to know some good practices and suggestions. Here ...
6
votes
4answers
92 views

Obj-C wrapper for OpenLDAP

This section of code reside in a utility class (LDAPUtility). It's purpose is to subscribe or unsubscribe a user from an LDAP group. My main questions are if I am using the LDAP library correctly and ...
3
votes
1answer
53 views

Test if a string is a number

In need for testing if a string is a number which could be a double or integer, I wrote a simple skeleton, which parses a string like this: ...
3
votes
1answer
39 views

Reading numbers from a text file into an array

I work in a project based on C language. I want to read a file that contains two lines of numeric characters. Example 9 8 9 5456 32 2 45 34 98 5 I want to ...
1
vote
1answer
72 views

Minimum Spanning Tree using Prim's algorithm and an indexed minimum priority queue

I have written some basic implementation of a Minimum Spanning Tree using a indexed minimum priority queue. For the implementation of the Priority Queue I used Sedgewick's Tutorials. However, it seems ...
6
votes
3answers
484 views

Representation of the formula P(n) = (n!)(6^n) in C

I'm trying to represent the following mathematical expression in C: $$P(n)=(n!)(6^n)$$ The first program should compute the answer to expression when n = 20. I have attempted to create the program ...
2
votes
2answers
54 views

Wrapper function to do polynomial fits with gsl in C++

I have two arrays of double, say x and y containing some physical data. I would like to find the best-fitting polynomial ...
4
votes
1answer
63 views

Palindrome Checker Algorithm

Here is an example of how I solved this problem (though this is not the only nor the best way by any means) for an assignment where it was also requisite to determine if a string was a reverse prefix ...
3
votes
5answers
506 views

Find smallest prime number greater than given n

I need to write a program which will find a prime number, greater than the given n. Can it be done simpler? ...
11
votes
2answers
372 views

Application for converting markdown to PDF

First time writing C in a long time and would like some code review to try and improve my code. I have some specific questions, but first an introduction to the code. The application is a simple ...
2
votes
3answers
115 views

Counting the out-of-order elements of an array

Is there any way to write that C function better so the procedure would spent less time to calculate the results? Assume that the array size is 1.000.000 and all the numbers are greater than 0. ...
5
votes
3answers
161 views

Printing the contents of a string array using pointers

I'm currently studying C and I'm trying to just print the contents of a string array. I'm using pNames to point to the first char pointer and iterating from there. ...
3
votes
5answers
359 views

Opening files using fopen only if user enters correct password

I wrote this program to just get some practice in C, but I have a question: Do you see anything that I am doing that will create bad habits in my future programming? ...
3
votes
2answers
64 views

Prints out to stdout all possible combination of printable ASCII 7-bit characters

This takes over 60 minutes to execute. The program is small in size, about 16kb. I am thinking that the repeated calls to printf slows it down significantly, rather ...
3
votes
2answers
38 views

Efficiency of sieve of Eratosthenes

Can I make this more efficient? ...
5
votes
2answers
100 views

toBase64 encoder

My code convert text to Base64. I used the algorithm without bit operations. What do you think about my code? ...
1
vote
1answer
58 views

Base64 encoder optimization

Base64 is a widely used encoding mechanism to allow arbitrary binary content to be transferred as printable text. This program is designed to take binary file as input and produce a Base64-encoded ...
5
votes
1answer
77 views

Custom Memory Allocator in C

I made this because I need to make a program that creates and destroys huge trees in gigabytes for hours or time. The default malloc/free in MinGW/GCC is too slow. ...
0
votes
2answers
25 views

Determining coefficient in geometric progression

For an assignment at Uni we had to code a program that takes numbers as input and determines the coefficient if they form a geometric progression once you declare EOF (ctrl+z). If the user inputs a ...
3
votes
4answers
145 views

Reversing a string in place without using iteration in C

This is function for reversing a string in C using recursive calls: ...
4
votes
2answers
60 views

Translation of Number Systems

My code converts a number from one number system to another (from binary to 36 and back). Do you think my formatting is successful or not? ...
2
votes
0answers
46 views

Treap with implicit keys

I implemented an implicit treap and tested it a little. It works fine but I'd like to know if there are ways to improve/simplify things and/or if some parts are incorrect. Later, I'll augment code to ...
11
votes
3answers
478 views

Implementation of an Stack without Linked Lists in C

I'm a beginning C programmer. As an exercise, I have attempted to implement a stack of strings in C. This is my first real exercise working with pointers. I looked at some other similar posts on here, ...
3
votes
3answers
55 views

Copy a directory from source to destination

I wrote a program that copies a directory from a source to a destination, similar to the cp utility. For this, I used the essential functions: ...
8
votes
4answers
740 views

Fruitmachine game

I'm quite happy with my code so far but I often make efficiency errors that I don't see when writing code. Have I missed anything? ...