cleaning things up a bit
This commit is contained in:
23
gowrikumar/src/00-sizeof.c
Normal file
23
gowrikumar/src/00-sizeof.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int array[] = {23, 34, 12, 17, 204, 99, 16};
|
||||
#define TOTAL_ELEMENTS sizeof(array) / sizeof(array[0])
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int d;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("sizeof(array) = %d\n", TOTAL_ELEMENTS);
|
||||
#endif
|
||||
|
||||
for (d = 0; d < TOTAL_ELEMENTS ; d++)
|
||||
printf("%d\n", array[d]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
20
gowrikumar/src/02-dowhile.c
Normal file
20
gowrikumar/src/02-dowhile.c
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* :author: Dan Buch (daniel.buch@gmail.com)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i = 1;
|
||||
do
|
||||
{
|
||||
printf("%d\n", i);
|
||||
} while(++i < 15);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
22
gowrikumar/src/03-stdoutbuf.c
Normal file
22
gowrikumar/src/03-stdoutbuf.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* :author: Dan Buch (daniel.buch@gmail.com)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("(Hit ^C to stop the madness.)\n");
|
||||
while(1)
|
||||
{
|
||||
fprintf(stdout, "hello-out ");
|
||||
fprintf(stderr, "hello-err ");
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
23
gowrikumar/src/03b-stdoutbuf.c
Normal file
23
gowrikumar/src/03b-stdoutbuf.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* :author: Dan Buch (daniel.buch@gmail.com)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("This time we'll include \\n!\n");
|
||||
printf("(Hit ^C to stop the madness.)\n");
|
||||
while(1)
|
||||
{
|
||||
fprintf(stdout, "hello-out\n");
|
||||
fprintf(stderr, "hello-err\n");
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
24
gowrikumar/src/03c-stdoutbuf.c
Normal file
24
gowrikumar/src/03c-stdoutbuf.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* :author: Dan Buch (daniel.buch@gmail.com)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("This time we'll flush stdout!\n");
|
||||
printf("(Hit ^C to stop the madness.)\n");
|
||||
while(1)
|
||||
{
|
||||
fprintf(stdout, "hello-out ");
|
||||
fprintf(stderr, "hello-err ");
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
19
gowrikumar/src/04-macrodef.c
Normal file
19
gowrikumar/src/04-macrodef.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* :author: Dan Buch (daniel.buch@gmail.com)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define f(a, b) a##b
|
||||
#define g(a) #a
|
||||
#define h(a) g(a)
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%s\n", h(f(1, 2)));
|
||||
printf("%s\n", g(f(1, 2)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim:filetype=c:fileencoding=utf-8
|
||||
*/
|
14
gowrikumar/src/Makefile
Normal file
14
gowrikumar/src/Makefile
Normal file
@@ -0,0 +1,14 @@
|
||||
# puzzles from http://www.gowrikumar.com/c/
|
||||
|
||||
BINDIR := ../bin
|
||||
|
||||
ALL_BIN := $(patsubst %.c,$(BINDIR)/%,$(wildcard *.c))
|
||||
|
||||
|
||||
$(BINDIR)/%: %.c
|
||||
$(CC) -o $@ $<
|
||||
|
||||
all: $(ALL_BIN)
|
||||
|
||||
|
||||
.PHONY: all
|
Reference in New Issue
Block a user