Add printf formatter

This commit is contained in:
caskd 2020-01-30 10:47:43 +01:00
parent cc8beab255
commit e2042e677f
No known key found for this signature in database
GPG Key ID: 79DB21404E300A27
2 changed files with 22 additions and 1 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
project(programmingquest LANGUAGES C) project(programmingquest LANGUAGES C)
SET(CHALLANGE namegen) SET(CHALLANGE format)
add_executable(binary add_executable(binary
src/${CHALLANGE}.c src/${CHALLANGE}.c

21
src/format.c Normal file
View File

@ -0,0 +1,21 @@
#include <stdio.h>
#include <stdlib.h>
#define COLIM 16
int main(int argc, char *argv[]) {
char c;
int count=0;
if (argc<1) {
fprintf(stderr, "No format provided!\n");
return 1;
}
while ((c=getchar())!=EOF) {
printf(argv[1], c);
if (count++==COLIM) {
printf("\n");
count=0;
}
}
printf("\n");
return 0;
}