Skip to content

Instantly share code, notes, and snippets.

@Learath2
Learath2 / 1-12.c
Last active August 29, 2015 14:04
//K&R2 Exercise 1-12 "1 word per line"
#include <stdio.h>
main()
{
int i;
for(i = 0; (i = getchar()) != EOF;){
if(i != ' ')
putchar(i);
else
//K&R2 Exercise 1-13 "Histogram of word lengths"
#include <stdio.h>
#define OUT 0
#define IN 1
#define MAX_WORD_LENGTH 20
main()
{
int c = 0, wl = 0, i = 0;
@Learath2
Learath2 / 1-19.c
Last active August 29, 2015 14:04
//K&R2 Exercise 1-19 "Reverse string"
#include <stdio.h>
#define MAX_LENGTH 1024
int getline(char[], int);
void reverse(char[], int);
int main()
@Learath2
Learath2 / 1-20.c
Last active August 29, 2015 14:04
K&R2 Exercise 1-20
#include <stdio.h>
#define TABSTOP 8
int mod(float, float);
int main()
{
int c, i, cc;
@Learath2
Learath2 / 1-21.c
Last active August 29, 2015 14:04
K&R2 Exercise 1-21
/*K&R2 Exercise 1-21 "entab"*/
#include <stdio.h>
#define TABSTOP 8
int mod(int, int);
int main()
{
int c, sc, col;
@Learath2
Learath2 / 1-22.c
Last active August 29, 2015 14:04
K&R2 Exercise 1-22
/*K&R2 Exercise 1-22 "fold"*/
#include <stdio.h>
#define MAXLINE 1024
#define FOLD 80
int getline(char[], int);
int mod(int, int);
int main()
@Learath2
Learath2 / 2-3.c
Last active August 29, 2015 14:04
K&R2 Exercise 2-3
/*K&R2 Exercise 2-3 "htoi"*/
#include <stdio.h>
#include <ctype.h>
int htoi(char[]);
int getl(char[], int);
int main()
{
char s[20];
@Learath2
Learath2 / 2-4.c
Last active August 29, 2015 14:04
K&R2 Exercise 2-4
/*K&R2 Exercise 2-4 "squeeze"*/
#include <stdio.h>
void squeeze(char[], char[]);
int main()
{
char s1[100] = "Test Mest Kest Sest Vest Mest";
char s2[10] = "sM";
printf("%s\n", s1);
@Learath2
Learath2 / 2-5.c
Last active August 29, 2015 14:04
K&R2 Exercise 2-5
/*K&R Exercise 2-5 "any"*/
#include <stdio.h>
int any(char[], char[]);
int main()
{
char s1[64] = "Test Tekt Takt";
char s2[10] = "ke";
printf("%d\n", any(s1, s2));
@Learath2
Learath2 / 2-6.c
Created July 30, 2014 15:34
K&R2 Exercise 2-6
/*K&R2 Exercise 2-6 "setbits"*/
#include <stdio.h>
unsigned setbits(unsigned, int, int, unsigned);
int main()
{
}