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.
-3
votes
0answers
20 views
-4
votes
0answers
19 views
calculate the first n primes (linux-windows bug) [on hold]
So I have this code working fine after compiling with mingw. Then it compiles under ubuntu-16.10 and when I execute it, it yields a floating point exception.
The command in both tests is the same:
<...
4
votes
0answers
61 views
Super calculator in C
For my mathematical research, I am to deal with very large numbers and I know that the standard C types are not going to stand a chance against them due to their limited capacity, so I decided to ...
1
vote
1answer
40 views
Find and print all numbers in a comma-delimited string using sscanf
I want to find all of the whole numbers in a string that starts with { and ends with }, and uses ...
-4
votes
0answers
37 views
Random number generator without duplicates in C [on hold]
I'm making a mastermind game in C and i want to generate the colors without any duplications
...
5
votes
1answer
43 views
Concurrent stack in C - follow-up
This is a follow-up question to Concurrent stack in C
The pop function not just removes the top element from the stack, but also returns it.
If a pthreads call ...
2
votes
2answers
63 views
Struct with abstract type member in c
I am writing C code that has some dynamic arrays/list that are represented with a struct that contains the number of elements and a pointer to the elements.
I have some functions that are doing some ...
1
vote
0answers
34 views
Handwritten parser for a language similar to C
I recently asked on a review about my C lexer. I've since learned more about parsing and Backus-Naur Form to make a Parser.
I'm planning to eventually install an AST to this Parser and create a ...
2
votes
2answers
85 views
Convert hours and minutes to total minutes
This is a simple exercise in C designed to work on IO. The purpose of the program is simple: convert a number of hours and minutes to a total number of minutes.
...
0
votes
0answers
18 views
Why am I getting garbage characters in my output for Test 1 and Test3 occasionally? [migrated]
I am having problems with my Test cases writing garbage to my result variable, and I am pretty new to C, so I am having trouble determining what is causing it. Thanks
...
-5
votes
0answers
17 views
Pass file lines to struct arrays [closed]
I'm trying to pass the elements of every file line into struct arrays. My program worked just fine before I implemented the while loop(I know less tasks), but now it crashes right away. Do I need to ...
-4
votes
0answers
18 views
function doesn't return long long int [closed]
I don't know why my function doesn't give the correct result.
I suspect that it doesn't return the right type (unsigned long long int), but it return an int instead.
...
7
votes
0answers
79 views
Vectorizing the product of an array of complex numbers
I am trying to write fast/optimal code to vectorize the product of an array of complex numbers. In simple C this would be:
...
3
votes
1answer
65 views
Measuring the length of binary numbers in English words in C
Inspired by this question (link to original video), I decided to write some code in C to perform this task, and it is much faster than the Python code, even when run with PyPY, up to a billion, it ...
-5
votes
2answers
56 views
Finding the largest prime factor of a 12 digit number [closed]
I created this using C++ and this gives the largest prime factor of a number.But my problem is if I try to find the largest prime factor of a very large number (12 digit number) it gives an error or ...
5
votes
1answer
54 views
C program for whitespace normalization
I have made a beginner program using C that uses file handling and formats the given file. Formatting includes removing trailing blank spaces, replacing one or more blanks by a single blank and also ...
5
votes
1answer
34 views
Get IP info from a FreeBSD machine
I'm try to get the public IP address from my FreeBSD machine and use it for the rest of my code.
Is this implementation good? Can it be optimized more? Can you see some gaps here? Something that ...
7
votes
2answers
92 views
Neural Networks in C
This block of code is one of my first C header files I have made; it's ported from a Python program I made a few months ago for a project.
I was just looking for advice on how to increase the ...
4
votes
2answers
70 views
File chunk buffer for Windows programs
The purpose of the ChunkBuffer code below is to designate a "chunk" from a given input file and to loop that chunk (if needed).
Its operation is similar to the ...
0
votes
1answer
64 views
A quartic polynomial in four variables, for numerical integration
About half year ago, I derived a integral of a piecewise polynomial, which was a complex formula. Below is one of that formula:
Obviously, the above formula has relationship with four varibles \$u_i,\...
3
votes
1answer
58 views
Assignement on reading from stdin in C
I am an experienced Python developer learning C. I solved this assignement:
Write a program that reads a word and some sentences from stdin. The word is separated by space from a sentences. The ...
5
votes
1answer
74 views
Remove all nodes that satisfy a condition from a binary tree
Assume a binary tree with a data structure like this:
...
1
vote
0answers
27 views
Breadth-First Search in C: Maze-like use of 2D arrays, linked list
Problem:
In a grid of nodes pick a starting node(has mode2), and using Breadth-First search, find one with a ending node (has mode1).
You can make walls so it's harder for the search. And that ...
1
vote
2answers
322 views
Dual state button algorithm in C
I wrote code for determining the push button state whether it is long pressed or not. This function is called by timer interrupt routine every 1ms.
But it seems really dumb. How can I make it shorter ...
7
votes
3answers
308 views
Homework / toy program - character matching
Given a string A = "Hello world" and another string B = "wor", I have to print ("TRUE" or "FALSE") whether the characters in <...
-6
votes
1answer
110 views
Word frequency counter - symbol table - array implementation
Symbol table
It is key-value pair abstraction
Insert a value with specified key
Given a key, search for the corresponding value
Here is the design for symbol table implementation for frequency ...
4
votes
2answers
77 views
Counting the number of words in a string using C
I wrote a simple program to count the number of words in a string using C. Would you mind reading it and telling me if the method used is acceptable? Or if there are style errors or ways I can improve ...
1
vote
0answers
90 views
List interface implementation
After following the comment from greybeard,
Below is the design for given first phase of implementation,
Code directory structure,
...
4
votes
2answers
103 views
Double-Pivot Quicksort in C
I've added a sort function to my library of utility functions. I will need to extend its behaviour at a later time but for now it's just a replacement for the ...
3
votes
1answer
83 views
Converting Integer to dynamically allocated Char array, digit by digit using pointers
Problem: Write a function to convert Integer to String, using only
pointers, without array indexes, string must be dynamically
allocated.
...
0
votes
0answers
31 views
2016 Advent of Code Day 3 Part 1 and Part 2
Continuing from earlier, here's a working solution to the Advent of Code Day 3.
With this one, a long list of triangle sides are provided, conveniently listed line by line. However, many of the ...
2
votes
0answers
29 views
2016 Advent of Code Day 2, Part 1 and Part 2
Continuing from yesterday, here's a simple solution in C to part 1 of Advent of Code Day 2.
I used a simple state machine to map from each keypad key to the next keypad key given the input.
...
6
votes
1answer
1k views
What's wrong with this FizzBuzz?
The rules are unsurprisingly:
Write a program that prints the numbers from 0 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For ...
6
votes
2answers
95 views
Concurrent stack in C
(See also the follow-up question.)
I was in the mood for pthread.h and decided to write a concurrent stack data structure. My requirements:
the stack has maximum ...
0
votes
0answers
56 views
Free hash table list in C
I'm implementing a hash table to store the list of binaries in /bin and /usr/bin for quick access in my shell. Is this the best ...
-1
votes
0answers
24 views
MSP430G2553 interfacing with an LCD screen
I'm curious to see if my C syntax and separation of code into a main, header, and C file was correct.
.h file:
...
3
votes
0answers
45 views
2016 Advent of Code Day 1, Part 1 and Part 2
I've been reading the Rust versions of this, and just because I'm kinda tired, I thought I'd just throw together something in C.
Here's my 15 minute effort to solve the 2016 Advent of Code Day 1, ...
2
votes
1answer
90 views
Priority queue implementation using unsorted and sorted array
Below is the unsorted array and sorted array implementation of priority queue.
Code directory structure:
...
11
votes
2answers
518 views
Learning pointers by implementing a basic linked list with tests
I wanted to learn about pointers and someone suggested that I give C a try, so I went through Linked List Basics from Stanford CS library, implemented some of the code (and tried to improve the code a ...
-1
votes
1answer
96 views
5
votes
2answers
106 views
Handwritten lexer
I'm in the process of designing my own programming language and I have absolutely no experience in computer science other than the code I look at.
I created my first lexer, I've improved it enough ...
6
votes
1answer
40 views
Arduino controller to control the backlighting of a gear selector
Background
The gear selector on a car allows the driver to select which state the transmission should be in.
In the example picture, one of the five letters (P, R, N, D & S) lights up to ...
22
votes
3answers
4k views
Decoding C program
I've built a C decoder program. The length of an encoded message will be given and the message itself in the following line. All the characters of the message will be in uppercase letters. The task is ...
-6
votes
1answer
126 views
My attempt at ProjectEuler #1
The task for Project Euler #1 is to find the sum of all the multiples of 3 or 5 below 1000.
Here's what I coded:
...
8
votes
2answers
112 views
entab program which replaces 4 spaces with a tab
I wrote an entab program which needs to replace every \$n\$ spaces with 1 tab. I picked \$n\$ to be 4, so every 4 spaces should be 1 tab. I have a feeling that my code is far too complicated than it ...
5
votes
1answer
78 views
Integer Log2 implemented using binary search
I saw a simple method to calculate Log2(N), where N is the power of 2:
...
8
votes
2answers
130 views
First small project - Snake in C
We started programming in school this year. I wasn't expecting to learn much but the pace is really slow so I tried to learn some things myself. I decided to do a little project for a start and that ...
0
votes
1answer
61 views
Adding bits, simpler
Considering that two bitsets are provided in the form of strings, char a[] and char b[], as in the code below. And the task of ...
12
votes
3answers
805 views
Endianness conversion in C
I have written a simple C header for converting the endianness of short integers and long integers. It uses the GCC macro ...
1
vote
4answers
77 views
Socket client in C using threads
I'm working on socket programming in C. I have no problem with usage the threads. This all works fine but I'm new in this area. I wrote this code in client.c but is there any misused code or something ...