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.
-2
votes
0answers
13 views
Sleep () function , issue in c++ [on hold]
i am trying to make a very simple keylogger using the GetAsyncKeystate
and i am adding the sleep function to reduce cpu usage ,however when i add
Sleep (1); it doesnt seem to pick up the keystrokes ...
1
vote
0answers
20 views
Cuda C Matrix Compression
I am using Cuda to learn and implement a CSR matrix compression algorithm. What can I do better relating to C's best practices?
main.c:
...
0
votes
0answers
26 views
Building a Stack with C structs
After reading the book from which this example is from I started using APIs like this
...
3
votes
2answers
36 views
Exercise 1-22 from K and R: line folding
I'm currently learning C with K&R, i'm right now in the exercise 1-22, but it's a little... hard to understand (at least for me). It says:
Write a program to "fold" long input lines into two ...
0
votes
0answers
13 views
3
votes
1answer
68 views
POSIX arithmetic expansion
I understand that a shell should be able to perform arithmetic expansion. My shell can do it:
$ echo $((1+2*3+4*5))
27
My solution uses the lemon parser where I ...
3
votes
1answer
42 views
Two variants of a picture database initialization routine
I wonder which of the two snippets is better? In the second one, I extracted two short subroutines.
On the one hand, extraction clearly separate the two tasks
On the other hand, it induces 6 more ...
4
votes
1answer
47 views
Allocating a contiguous block of memory for an array
I try to work with a contiguous block of memory, to create an array (2D) whose SIZE is not known at compile time (before c99) so no variable-length arrays are involved here.
I came up with the ...
0
votes
2answers
39 views
Two variants of a db_create_ressources(…) function
After reading noobs, I'm interested in possible way to improve readability of the following short snippet.
a struct pictdb_file is a small file system containing ...
6
votes
4answers
348 views
Custom user input function
The program consists of 3 files: demo.c, mylib.c and mylib.h. The code is heavily commented.
...
0
votes
0answers
19 views
Recursive spinlock for C using ASM
My history of C/ASM locks here in codereview:
Simple spinlock for C using ASM
Simple spinlock for C using ASM, revision #1 (basis for this approach. If this one fails, then so will the one below.)
...
3
votes
0answers
33 views
Time Limit Exceeded with shortest path algorithm
The problem:
SHPATH
You are given a list of cities. Each direct connection between two
cities has its transportation cost (an integer bigger than 0). The
goal is to find the paths of ...
2
votes
1answer
28 views
Simple pool of threads which calculate the sum of a given number from the main process
I have to make a program which creates a number of threads that are waiting at the beginning, then the main process creates a doubly linked list where random numbers are put and then a signal tells ...
3
votes
1answer
41 views
Testing different implementations of malloc()
Can you help me verify my test result? I'm testing different malloc() implementations with a small program that allocates gigabytes many times:
...
-3
votes
0answers
23 views
Pointer Manipulation C [closed]
I am getting a pointer in a function of type BYTE * where BYTE is nothing but
typedef unsigned char BYTE;
Now, if i am converting the BYTE * pointer to int * ...
3
votes
3answers
86 views
Counting the number of primes in C and C++11
I found this old piece of code that I wrote while I was learning C a while back:
...
2
votes
0answers
34 views
Simple spinlock for C using ASM, revision #1
Revision #1 for Simple spinlock for C using ASM
The code:
...
4
votes
1answer
53 views
Simple spinlock for C using ASM
This is my second attempt to make simple lock using extended assembly.
See http://stackoverflow.com/questions/37241553/locks-around-memory-manipulation-via-inline-assembly/37246263
The code:
...
1
vote
1answer
54 views
1
vote
0answers
27 views
Convert tri-gram of type wchar_t to an integer type
I am trying to convert a tri-gram containing 3 characters of type wchar_t to an integer type (an uint64_t at the present time).
...
1
vote
1answer
77 views
Reading from text files in C/C++ [closed]
I'm writing a program that has to check which are the two largest three digit numbers that are missing from a text file. I'm writing this in C++ and I'm trying to solve the mystery in a ...
3
votes
3answers
32 views
Array-based queue implementation using C
I wrote this header for generic use of a queue. The one thing I'm wondering is if I understood the usage of void*. I hope that if somebody teach me some conventions ...
3
votes
2answers
49 views
C - Improving (really) big number addition
I was lucky enough to stumble into this task during a job interview. I was gently guided to use string reversals and a few other things to speed up my process. I kept thinking that I wouldn't have ...
3
votes
1answer
56 views
Running shell commands in a pipeline
I'm writing a shell in C for Linux and BSD. My code was unreadable before but I did a rewrite and now it is much more readable. The purpose of the code is to create a command pipeline and execute it.
...
4
votes
1answer
36 views
Secure file system utility functions
For Khronos, I've had to develop these utility functions to help me deal with storing the .wav files. However, they could also be used in a variety of ...
4
votes
2answers
70 views
Recreating strstr in C
I'm trying to recreate strstr in c, my code works but I think it is too long, and it needs some improvement.
...
14
votes
2answers
341 views
The birth of my intelligent assistant: Khronos
I've done a lot of reworking to this main file recently, in regards to using a new speech recognition engine and integrating the last reviews suggestions. My question before is going to be phrased ...
2
votes
1answer
41 views
Median of 3 Quicksort in C
I'm trying to re-implement the C stdlib function qsort using a median of 3 quicksort.
...
5
votes
3answers
99 views
Simple file renamer in C
It's been some time since I wrote something in C. I am looking for some advices related to my code in terms of coding style, bad/wrong logic, optimization (performance) and good practices.
The code ...
2
votes
1answer
51 views
Optimizations for bubble sort
The code performs bubble sort on the basis if any swaps has been performed in the iteration. I made it sort of independent of number of iterations as in any conventional bubble sorting code.
I went ...
3
votes
1answer
26 views
AES Wrap function
This code is supposed to implement RFC 3394 which also described in this PDF at page 11.
Are there any weak places or formatting issues in attached source? Or maybe some places are not explicit ...
3
votes
1answer
66 views
Small Poker program in C
I made a small Poker program with C but I believe I could've written it better.
Full source on bitbucket.org
...
4
votes
1answer
41 views
Automake for an S/KEY implementation
I've been tasked with giving a legacy codebase some love. The actual code is written in C, but is not very relevant aside from the #includes each file makes. No, ...
-4
votes
0answers
33 views
Printing numbers to a given number n and calculating the sum and count as well [closed]
This prints numbers to a given number n and calculating the sum and count as well, but my program is giving "time limit exceeded." Please suggest ways to reduce the complexity.
...
-5
votes
2answers
48 views
Rewrite 12 consecutive ints based on bizarre logic
Despite looking terribly ugly, it is pretty interesting due to some specific connections to cellular automata theory. I'm looking for ways of simplifying it further. This program takes 2.7 seconds to ...
-3
votes
1answer
41 views
Creating a struct
Mat told me to create a struct
create a struct for the individual commands and arguments. It should
have something like the "executable" name, number of args and arg
list. Create a few ...
1
vote
1answer
49 views
0
votes
0answers
23 views
Prefetch in ARMv7
I have to implement Khatri Rao product between 2 matrices in C. Mathematically this is a column major access of data and I can not change that. But if I use preload ( PLD instruction in ARMv7 ) to ...
-3
votes
1answer
52 views
Printing a prime normalized sequence
The program below generates a prime normalised sequence. So, what happens is this:
It asks you to provide a number within a range. Program then calculates a factor which is inverse of product of all ...
1
vote
3answers
42 views
C single-linked list with remove
Can you please point out any problems with this C forward list with remove node functionality?
I believe this can be way simpler ( removeNode function ) but I ...
0
votes
1answer
24 views
C function for copying array into matrix
I want a matrix that can grow dynamically and build up a structure in RAM as input arrives from standard input och terminal (shell). First I tried with a matrix like ...
3
votes
2answers
314 views
C dynamic array implementation using preprocessor
I have implemented a generic dynamic array implementation using defines. As I am new to C, I am not sure whether the code has any flaws. The code is as follows,
...
4
votes
1answer
51 views
Program to convert binary to hex
I wrote this program to convert binary to hex, it ignores other characters between the binary digits. I would like to receive any recommendations on how to improve it.
...
2
votes
3answers
53 views
Parabola calculations - follow-up
Previous question
After applying the suggestions, I wanted to revise the question with the new code because I don't think this is good enough.
...
2
votes
1answer
73 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
46 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
61 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
57 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
204 views
Parabola calculations
I'm trying to make a small parabola calculator just for fun. Is this code good?
...
7
votes
1answer
53 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 ...