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

1
vote
1answer
19 views

Parabola calculations revised

After applying the suggestions, I wanted to revise the question with the new code because I don't think this is good enough. Previous question ...
0
votes
0answers
15 views

Error-handling for several projects

I plan to use this error handling for several projects (my own CLI, my own memory management, my own debugger, my own testsuite). I'm still a beginner at this detailed level of C programming looking ...
0
votes
1answer
22 views

Testing a shell command interpretor

I've written tests that use Bash for testing a custom shell. I think the tests work but I'm sure you know better because this is my first test I write this way. ...
2
votes
1answer
42 views

Find the contiguous subarray within an array (containing at least one number) which has the largest sum

Interview Q: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example: Given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray ...
0
votes
1answer
32 views

Shell command line program

I have refactored a for loop into a function. I'm still a beginner at using C utility functions such as strtok, ...
4
votes
1answer
44 views

Bubble Sort in C

I am trying to learn C coming from Python. Below is an implementation of bubble sort, slightly optimized. Any advice on best practices, readability, use of macros, and edge cases would be greatly ...
6
votes
2answers
191 views

Parabola calculations

I'm trying to make a small parabola calculator just for fun. Is this code good? ...
7
votes
1answer
30 views

Social network graph of characters in a novel

I wrote a C program that builds a social network graph of characters in a novel. The program takes two text files as input: a list of the names of the characters in the novel, and the file of the ...
2
votes
2answers
36 views

Shell command-line interpreter with pipeline parsing

Like many others I've been writing a shell command-line interpreter that can do a pretty decent pipeline parsing, first it splits the command at pipeline char (|), then it splits the substring at ...
0
votes
0answers
11 views

Reservoir sampling implementation in C

The distribution of unique values in input and output seems to be quite different in the following code, (h1), (h2); does the implementation have any obvious error ? ...
1
vote
1answer
28 views

Makefile and main header file for a shell

My main.c includes this header file. Please let me know how I can improve it. I did my best but I don't know much about code conventions in C (I come from Java and ...
2
votes
2answers
35 views

Print how many times a sequence of characters appears in a string

Given a string, count how many times a sequence of characters (in this code, the sequence is "ei") appears until the user types '#', then print the amount. I would like to know how to improve the ...
2
votes
2answers
61 views

Calculating the sum of the digits in 2^1000

I have a program which calculates the sum of the digits in the number 21000. The program is not beautiful and I was hoping for some advice on how to improve it. The idea I have used is to create an ...
1
vote
1answer
33 views

Alternative to using strncpy() as 'safe' version of strcpy()

I am thinking of using this as part of a header file to give me a useful string-manipulation tool. Elements is size of dest to prevent overflow: ...
-2
votes
0answers
35 views

Am I writing this insert function for a linked list in c++ efficiently? [closed]

By efficiently I mean, using as little lines of code and if there are any errors please point them out. Thank you. ...
0
votes
0answers
27 views

Multithreaded client socket

This is my first time working with networks and multithreading in C, and would like to know how to make improvements. I wanted to make a client program that handles reading and writing to the server ...
-3
votes
0answers
57 views

Speeding up code (beginner) [closed]

So I've written some code that I'm sure can be done quicker and more effectively on my micro, but I just can't my head around it. (using TM4C1294xl in CCS) I have an interrupt which I want to read the ...
4
votes
1answer
77 views

Sort algorithm in c

I wrote this algorithm a while ago, and decided to revisit it and polish it up. It basically works by comparing each number with all the other numbers once, so comparing the first number to all ...
15
votes
5answers
2k views

Word Inverter in C

I've just made this program and I want to know how to improve it. It just receives a word and prints it backwards. Sequences of numbers are also accepted, but not white spaces (that's why I used ...
5
votes
1answer
61 views

run command pipeline in C

This code parses and tokenizes my shell language command interpreter. I will try and make it 2 functions, one that is the tokenizer and the other that is the rest of the function. Can you find ...
3
votes
1answer
51 views

How to make doubly linked list design more efficient?

I have played recently and implemented doubly linked list with merge sort algorithm. I was wondering if there is any way of improving the algorithm further to make it as fast as possible (I know about ...
4
votes
2answers
80 views

Convert integers into binary

I've made a very simple program that takes integer number arguments either with plus/minus sign or without them, and print the number in binary format. binary.c ...
4
votes
2answers
45 views

Alphabetic Pattern Pyramid

I want to know if I can improve this program. Its goal is to print a pattern in a pyramid form, by first receiving a letter. The first row is always 'A', only. Then 'ABA', then 'ABCBA'. Increasing ...
2
votes
1answer
41 views

Optimizing quicksort partition method/function for duplicate elements

I'm a newbie and interested in learning different data structures and algorithms. While implementing quicksort, I found this code works pretty well for partitioning. ...
1
vote
2answers
65 views

linked list in c code

I have implemented linked list data structure in c. linkedlist.h ...
-1
votes
0answers
46 views

png2jpeg, a utility for converting PNG to JPEG (rev. 3/3)

Revisions: Revision 1 Revision 2 Revision 3 (you are here) png2jpeg is a simple command-line converter of PNG to JPEG. The source code requires the libpng and libjpeg development libraries to be ...
2
votes
1answer
42 views

A framework for simple multiple-choice quizzes

Just looking for more experienced programmers opinions on this code. It's a framework for making simple multiple-choice quizzes. I am aware that there is the potential to make the arrays dynamic, but ...
1
vote
1answer
59 views

My Queue implementation is correct?

I have read CLRS Introduction to Algorithms book, now I'm on Elementary data structure chapter. I read about queue concept and try to implement in c. I have tested a lot it work fine, but I have a ...
0
votes
0answers
46 views

A cast(type, expr) macro that can be used in C or C++

I had the idea to make some casting macros which could enable "extra checking" for C code, if that code happened to also be compilable as C++. The goal was to make the casts easier to see, as well as ...
2
votes
2answers
39 views

Remove all occurrences of a digit from a number

I need to remove all occurrences of a digit from a number in a recursive function with this prototype: unsigned rem(unsigned num, unsigned dig); This is my ...
3
votes
2answers
57 views

Function that strips trailing '0's from a float

I'm writing an embedded application in C, and at one point I need to convert a float into an ASCII representation of that float, so I can send the ASCII over a serial port. The protocol the serial ...
-1
votes
1answer
65 views

C stack for Linux and BSD

My stack uses char data and is not tested. I use it to save command in a unix pipeline for my own POSIX shell. Maybe you can find a bug or a possible improvement. ...
2
votes
1answer
45 views

C main function for POSIX shell

I got a pretty large main function that I want to break up in smaller helper functions. Can you help me suggest what to break out into helper functions? The ...
2
votes
2answers
122 views

png2jpeg, a utility for converting PNG to JPEG (rev. 2/3)

Revisions: Revision 1 Revision 2 (you are here) Revision 3 png2jpeg is a simple command-line converter of PNG to JPEG. The source code requires the libpng and libjpeg development libraries to be ...
0
votes
1answer
23 views

Handle builtin commands

I've written a small C function to handle the builtin commands of a custom shell that I'm writing in C. Is it better to use a switch instead? ...
2
votes
1answer
52 views

Dynamic array stack and bag implementation

I've have methods for a stack and bag using a dynamic array in C. As far as I can tell everything is implemented correctly, but I'm wondering what I can do to improve this code. dynArray.h ...
3
votes
1answer
63 views

Generic variable-size array

As stated in the tags, I'm a beginner to C. This code implements a dynamic array (List in .NET, vector in C++, etc) for any ...
3
votes
0answers
32 views

Producer Consumer in C

I'm doing multithreading at university and we've been asked to implement the producer consumer problem in C. My code compiles and produces the right result. From debugging it, it seems to be waiting ...
-1
votes
1answer
57 views

Tokenizing a shell command

I want to handle input like the following ls -al | awk '{print $1}' Now to parse it I couldn't tokenize at whitespace because of the quotations and I had to make ...
2
votes
1answer
32 views

C function to find the less program

I've written a C function to find the program less that the operating system should provide. If lessis not provided, some other ...
11
votes
1answer
76 views

Recreation of cat in C

I have a school project to create a program that works the same as the Linux cat. The code works, but I just need find out where I can Improve it or handle errors. ...
0
votes
1answer
33 views

Prime numbers in given range

SPOJ problem PRIME1 (also found on other sites in identical form): Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are ...
0
votes
2answers
46 views

Create an array with at least a given number of bits

I use this declaration for an array which must contain a bit for every minute in a day: ...
7
votes
2answers
223 views

png2jpeg, a utility for converting PNG to JPEG (rev. 1/3)

Revisions: Revision 1 (you are here) Revision 2 Revision 3 I've been working on a simple command-line png2jpeg utility. Its purpose is to convert images from PNG format to JPEG. The source code ...
1
vote
1answer
56 views

A small timer in C

I needed to make a timer to profile small programs a while back. My use wasn't for a major project or mission critical code or anything even remotely close to that, just for personal learning ...
4
votes
1answer
34 views

C Version of a Client/Server application

Starting to write an article about Socket Programing. So I need a simple C version of a client/server app. So here it is for review (Also on github) A linked question is the C++ version MakeFile ...
-4
votes
0answers
36 views

Word Puzzle Solver

What my code does is that, it asks the user for a word, and then searches for that word in the puzzle provided. If the word is found, that word is capitalized. The full code is beneath! ...
5
votes
1answer
61 views

K&R 1-20 Solution

I'm currently reading the infamous K&R C book and trying to solve Exercise 1-20. My solution looks kind of too simple, but it works. I've searched the web for different solutions, but they all are ...
3
votes
2answers
142 views

Integer factoring in C using GMP for numbers

Anything you would change in the following code? It performs integer factoring using the GMP library and also can use OpenMP for parallel computation. I compile it using: gcc -lgmp -fopenmp and what ...
3
votes
3answers
114 views

Primitive console string calculator in C

Recenlty I have finished this primitive console string calculator in C. I need your balanced criticism, I'd like to know what I have to correct, remake and learn. Permitted operations: ...