C is a medium level general purpose compiled language.

learn more… | top users | synonyms

0
votes
0answers
9 views

Can someone check my ROBOTC Jeopardy Program?

I have tried to comment my code as much as I can. If you have any questions about it, please feel free to ask. The code it self should have a lot of details and the comments mostly explain what is ...
0
votes
0answers
10 views

C strings and character input, comparison [on hold]

I am learning c programing, for exercise I found a task to solve. It is something like a game hanging where someone chooses a word and other person guess letters. I have to check how many given words ...
0
votes
0answers
13 views

Stdin skipping fgets? [on hold]

My teacher wrote this, and I'm not sure if it works on her machine. I was supposed to add the line that says stuff = (char*)malloc..., which I believe is correct, but now I'm trying to test to make ...
0
votes
2answers
58 views

C code displaying random datasets

I have much more experience with PAWN scripting language, but I'm digging into K&R book (I think it is it), and trying some stuff on my own. #include <stdio.h> #include <stdlib.h> ...
1
vote
3answers
82 views

Doubly linked list implementation in C

I'm quite new to C, and I'm looking for feedback on this (doubly) linked list code. Once I get to the add and remove methods, I feel like the code goes downhill. I'm looking for any potential errors ...
0
votes
0answers
49 views

Embedded conditional code compaction

I'm porting some AVR code from PROGMEM/PGM_P to __flash, and I want to reduce the amount of conditional compilation I need to do in the code. Here's all the code (but keep in mind that only the parts ...
2
votes
0answers
49 views

Elegant way of writing JSON parsing function in C

I'm making a server in C that needs to parse JSON that follows Obix protocol and I'm using the Jansson library for this. I've been programming in high level languages such as Java and C# for my entire ...
3
votes
4answers
135 views

Reviewing my implementation of a stack using linked list

I have been studying data structures, and I'm new to this. Here is my code for the push and pop operations. I considered using a node=top, so that I can avoid O(n) operations for the push (i.e. ...
0
votes
1answer
37 views

Is there a better way to read in different datatypes from a file?

I'm making a database program that reads from a file info on tennis players. Everything works, but it seems like there would be a simpler way of doing that? Anything I can improve here? #include ...
2
votes
1answer
71 views

Review of singlely linked list C

I posted a couple of weeks ago with a double linked list. It was recommended that I rewrite the code as a singlely linked list and replace the recursive parts with loops. I've gone ahead and made ...
5
votes
4answers
285 views

Organizing semaphores into a pyramid

My homework was to organize semaphores into a pyramid. The task was accomplished, but I ended up with this long ugly conditional and was wondering if anyone can see a better way/algorithm to ...
0
votes
0answers
40 views

Signal Simulation through python scrits using shared memory for testing a C application

This is bit long, but I need to explain something before I can ask for actual reviews/advices. I've to test generated C codes from simulink model (Matlab). I can create a executable binary from those ...
1
vote
1answer
38 views

Is a Recursive-Iterative Method Better than a Purely Iterative Method to find out if a number is prime?

I made this program in C that tests if a number is prime. I'm as yet unfamiliar with Algorithm complexity and all that Big O stuff, so I'm unsure if my approach, which is a combination of iteration ...
1
vote
1answer
76 views

Visualization of bubble sort in progress

I've written a program showing the process of bubble sort arithmetic in C. I need some suggestions on improving it. #include <stdio.h> #include <Windows.h> #include <stdlib.h> ...
5
votes
1answer
77 views

Is the following a good C program for launching an interpreted script?

I was just wondering if this is a good example, following good practices, of a C program for launching an interpreted script from a native binary executable. Here the interpreter is Perl and the ...
0
votes
1answer
23 views

Optimised library database code for sorted array of structures

I have an array of structure records and function intersection and difference. The intersection function take list1,list2,list3(an array of records),and size of both list1 and list2. Here, ...
3
votes
2answers
51 views

Thread-safe linked list review

I want to implement a thread-safe singly linked list in C. Its nodes contain unique entries and I only need functions to add nodes (to head only), remove nodes and to locate a specific node. I am ...
0
votes
2answers
81 views

Run-length encoding using C / C++

This is my first post on Code Review. I have already asked this question on Stack Overflow and was asked to post it here. Here is the link. Recently I was asked in an interview to convert the string ...
2
votes
1answer
109 views

Is this an elegant/accurate simulation of the Monty Hall problem?

I'm trying to simulate the Monty Hall problem, to statistically determine if there is any benefit to changing my choice after a door containing a goat is open (testing this guy's Monty Hall theory on ...
1
vote
1answer
37 views

Reducing steps for long addition program

This is a program that I wrote to add two numbers together that are too large for the C language to store. It stores the numbers as strings instead and processes one digit at a time. But I suspect ...
1
vote
1answer
33 views

Is my code portraying the diagram correctly?

Here's the image: What my function does, is it takes the values of the profit (function declared as fieldProfit) and the field score (function declared as fieldScore); and if both are above 10, then ...
1
vote
0answers
49 views

Improving readability of Boolean adder generator?

Today I've noticed that the source code for a Boolean adder is very repetitive, so I wrote a Python script to generate the C source code. The script generates an adder of varying size depending on ...
23
votes
3answers
1k views

Why is my C program for calculating Euler's constant of poor quality?

I was trying to post this code to a Wikipedia article, but it was soon removed. I then asked about the code in the page's talk section, and some other contributors said that is was "very poor" and ...
1
vote
2answers
61 views

Floating-Point data input in Bash and C

I wrote a function that dynamically stores statistical data. I tried to clone the functionality of how I had originally written my solution in Bash. Is there perhaps something I could improve, or do ...
0
votes
1answer
51 views

Parsing function review. How to improve it?

I've written a function to parse configuration files, it doesn't handle file opening, instead it takes an array with the file contents, tries to find fields based on an array containing the fields' ...
2
votes
1answer
49 views

Matrix Transpose Function in C - Improve Performance

I have a matrix transpose function that takes arrays with a possibly different number of rows and columns. How to improve performance and code quality? void matrix_transpose(float *matrix, int rows, ...
1
vote
0answers
15 views

Not able to debug fault in Circular List Traversal Engine Algorithm [closed]

I want to traverse a circular linked list (v1->v2->v3) in a given input order, lets say like {v1,v3,v2,v2,v1,v3,v2,v1,v1,v3,v2,v2,v1,v2,v3}. I wrote the below program as test for 3 nodes and ...
1
vote
0answers
28 views

C: File locking between server threads

I have written below code where the server is getting requests from clients on socket and creating a thread per client. Each client thread is then writing to a file which is common to all the threads. ...
0
votes
1answer
55 views

Critique a beginners linked-list implementation

I am new to C, and this is my first attempt at creating a linked list. If anyone has a minute and could point out any errors or bad practices in this small linked list program, it would be really ...
7
votes
2answers
132 views

Usage of a C library in a C++ project (std::string char array conversion)

Abstract I have little C/C++ skills. I've learned programming mainly with Java, and so I chose C++ (targeting C++11) as the language to learn better. In my current C++ project, I have to use the ...
5
votes
1answer
100 views

Is this implementation of binary search correct?

Is this implementation of binary search correct? Any special or edge cases that I missed out? Maybe it should be optimized for elements that are less than the first element of the array or greater ...
4
votes
2answers
69 views

Memory Management For Small Allocations in C

This is my first attempt at doing this, so I know this code is probably bad. I would like to know exactly what is wrong with it, so I won't make the same mistakes again. This code is for a program ...
0
votes
1answer
33 views

Macros To Detect UTF8 in C

I'm working on a program that handles UTF-8 characters, I've made the following macros to detect UTF-8. I've tested them with a few thousand words and they seem to work. I'll add another one to do ...
0
votes
2answers
51 views

Making each module expose an interface

Is this a good/correct way to write a robust C program? //File1 => Module1.c static int Fun(int); struct{ int (*pFn)(int) }Interface; static int Fun(int){ //do something } Interface* ...
5
votes
2answers
64 views

Please review my FIR filters

I wrote 2 filters in C for the Altera DE2 Nios II FPGA, one floating-point and one fixed-point. I've verified that they perform correctly and now I wonder if you can give examples for improvement or ...
1
vote
3answers
151 views

Improve nested loop for bio-statistics calculation

I am doing a bio-statistics calculation and the following code works. However, can someone help to improve the messy nested loop? for(int i=0; i<NN; i++) { for (int j=0; j<NN; j++) { ...
2
votes
2answers
73 views

Bouncing-ball simulation

I posted a couple questions about a week ago, but have almost gotten it working. This program is supposed to simulate the following: Ask the user how many balls to drop Drop one ball at a time ...
0
votes
0answers
19 views

Can someone review my Rational implementation?

The header file can be viewed here. #include <stdio.h> #include <stdbool.h> #include <math.h> // searches default library classpaths #include "Rational.h" // searchs my directory // ...
1
vote
1answer
30 views

Can someone review my Polynomial data structure?

The following is working but I just want to know if I can make it better in any way. The header file can be viewed here. #include <stdbool.h> #include <stdlib.h> #include "Polynomial.h" ...
0
votes
1answer
45 views

Computing leading set (compiler design)

I have written this program to compute the leading set of the following productions E->E+T E->T T->T*F T->F F->(E) F-># Here identifier is taken as '#' #include<stdio.h> ...
1
vote
2answers
46 views

Binary search on cstrings

This implements binary search on an array of cstrings. One thing I'm wondering about is it faster or slower to pass a variable as const i.e. len. Also strcmp() gets called a lot and since I can't find ...
3
votes
3answers
151 views

Is this the best way to reverse a string in C (not in place)?

Here is my code. Is there anyway to make it more efficient? /* IN: string to have characters reversed OUT: string containing characters in reversed order */ char* reverStr(const char *str) { ...
1
vote
0answers
122 views

Computing first and following sets (compiler design)

I have made this program to find out the first and following sets of the productions: E->TA A->+TA A->0 T->FB B->*FB B->0 F->(E) F-># Here epsilon(NULL) is taken as 0: ...
0
votes
0answers
16 views

Implementation of StrRCSpn and StrRCSpnI

I found that Shlwapi.dll only had "find first occurrence of any of a group of characters" implemented as StrCSpn and StrCSpnI, and not "find last occurrence of any of a group of characters", so here I ...
1
vote
2answers
39 views

Acceptable Use of the goto Statement?

So, I made a console interface. It prompts users with several options they can enter. 1 for the first option, 2 for the second option, etc. Using the switch statement, each option will bring them to a ...
4
votes
1answer
86 views

Parsing expressions using idiomatic C

I'm a C++ programmer using SPOJ problems to learn C(99). This is my solution to the problem CMEXPR, where the goal is to read a valid expression (+, -, *, / only) from input and write it on output ...
2
votes
1answer
38 views

Function equivalent to strcmp

I'm starting out and need feedback in order to discover what are the things I'm doing wrong. This is supposed to behave like strcmp: int compare(char *str1, char *str2) { while(*str1 || *str2) ...
3
votes
2answers
73 views

Simple linux char driver, am I following recommended and modern idioms?

Since the resources I found to learn are generally out of date, I'm having to read a lot of documentation, which makes the learning process somewhat haphazard. The module makes a simple character ...
3
votes
2answers
96 views

K&R 1-20 Suggestions for Style and a better C Paradigm

I'm learning C with K&R 2nd Ed. I just completed ex 1-20 (which is the detab program). I was hoping to get some feedback on my work. I want to make sure that I am taking a good C approach and ...
4
votes
0answers
113 views

Is this CPUID parser ideal for any usage?

NOTE: I'm not perfectly sure of some of the parsed data, so any corrections are more than welcome. Parser (cpuid.c): #include <stdint.h> #include <string.h> #include "cpuid.h" enum { ...