Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 133688

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.

5 votes
2 answers
2k views

Replace n or all occurrences of substring in C

I wrote this code as an answer to a question. But I'd like you to have a look at it. This post is basically a copy of the answer I posted. The code does no error checking. It assumes that the output b …
klutt's user avatar
  • 903
3 votes

Substitution Cipher in C

My first suggestion is actually to remove most of the comments. Sometimes comments are useful, but when they are explaining obvious things, they just clutter the code. Also, since validate checks the …
klutt's user avatar
  • 903
3 votes
1 answer
746 views

Simple stopwatch in C

A very simple stopwatch. Intended to be used for simple benchmarking when you want to do a task several times, but exclude some setup code from the benchmarking. Some things I have already considered: …
klutt's user avatar
  • 903
4 votes
1 answer
1k views

Macro for counting number of elements in an array

We all know the classic version of counting the number of elements in a C array: sizeof(a)/sizeof(*a) But this is dangerous, because if used on a pointer it will return garbage values. …
klutt's user avatar
  • 903
6 votes
Accepted

Determining whether a provided credit card number is valid according to Luhn’s algorithm

First thing I think of is that you have a pretty long main. You should split the code in more functions. Your code could look like this: long long readCardnumber(); bool validateChecksum(long long ca …
klutt's user avatar
  • 903
1 vote

Given a series of characters from stdin, print their squared integer ASCII counterparts

When it comes to performance, the only real way to know which method that is faster is to benchmark it. In many cases we can make educated guesses, but nothing can replace testing the code. Once snipp …
klutt's user avatar
  • 903
1 vote

Implementing an alternative to scanf

(Apart from that, for fgets(sData, 20, stdin) you have to declare sData to have a size of at least 21 if you want to treat it like a regular C-string. Don't I need to free() in every case? …
klutt's user avatar
  • 903
4 votes

My own algorithm to sort integers

I would do six changes: Better variable names, especially for the arguments Remove unnecessary temporary array Handle negative numbers Initialize temporary array with memset instead of a loop. Comme …
klutt's user avatar
  • 903
8 votes
5 answers
5k views

Macro for allocation in C

As we all know, the syntax of allocating memory is a bit clunky in C. …
klutt's user avatar
  • 903
2 votes

Understand the dependency levels of makefiles

is a source file (dough) SRC = $(wildcard *.c) # Every source file should be compiled to an object file OBJ = $(SRC:.c=.o) # Every object file should have a dependency file DEP = $(OBJ:.o=.d) # Link the … exe from the object files $(EXE): $(OBJ) $(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS) # Generate dependencies for the object files %.o: %.c $(CC) -MMD -MP -c $< -o $@ # https://stackoverflow.com/q/2145590 …
klutt's user avatar
  • 903
5 votes
Accepted

TicTacToe classic in C

malloc I start with one of the most common ones. Instead of char *board = malloc(sizeof(char) * BOARD_SIZE) write char *board = malloc(sizeof(*board) * BOARD_SIZE). If you decide to change the type i …
klutt's user avatar
  • 903
3 votes
Accepted

State machine translates text into executable python code [v2]

Choice of language I understand you probably want to do this in C, but I felt it was worth mentioning that Python is a much more suitable language for this task. … ptr) is so common in C that it adds almost no readability. Comments You're using some unmotivated comments. Like when you are wasting 7(!) …
klutt's user avatar
  • 903