Skip to content

Instantly share code, notes, and snippets.

@giorgi568
giorgi568 / atof.c
Created August 10, 2024 22:51
the c programming language book, exercise 4-2
#include <stdio.h>
#include <math.h>
#include <ctype.h>
/*
code is from the book, i changed atof function to
make it handle scientific notations like :
"123.45e-6"
*/
@giorgi568
giorgi568 / strindex.c
Created August 10, 2024 17:30
the c programming language, exercise 4-1
#include <stdio.h>
#include <string.h>
/*
code is from the book i only modified strindex,
which now returns rightmost occurrence of t in s
*/
#define MAXLINE 1000
@giorgi568
giorgi568 / itoa.c
Created August 9, 2024 14:50
the c programming language book, exercise 5-6
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
/*
code is from the book, i only added minimal witdth -- w
*/
void itoa(int n, char s[], int w);
@giorgi568
giorgi568 / itob.c
Created August 9, 2024 14:32
the c programming language book, exercise 3-5
#include <stdio.h>
/*
itob(n,s,b) converts the integer n into a base
b character representation in the string s.
b could be up to 36. after that we run out of letters.
*/
void itob(int n, char h[], int b);
void reverse(char s[], int len);
@giorgi568
giorgi568 / expand.c
Created August 7, 2024 22:20
the c programming language book, exercise 3-3
#include <stdio.h>
void expand(char s1[], char s2[]);
void expand(char s1[], char s2[]) {
int i, j, l;
char start, end;
start = end = '\0';
l = 0;
@giorgi568
giorgi568 / any.c
Created August 4, 2024 10:56
the c programming language book, exercise 2-5
#include <stdio.h>
/*
this is supposed to return first location in
string s1 where any character from the string
s2 occurs, or -1 if no such occurances exist.
*/
int any(char s1[], char s2[]);
int any(char s1[], char s2[]){
@giorgi568
giorgi568 / squeeze.c
Created August 4, 2024 10:55
the c programming language book, exercise 2-4
#include <stdio.h>
/*
this is supposed to remove any character in
string s, which also happens to be in string c
*/
#define IN 1
#define OUT 0
@giorgi568
giorgi568 / htoi.c
Created August 3, 2024 21:53
the c programming language exercise 2-3. (hex to int)
#include <stdio.h>
#include <ctype.h>
int expo(int x, int y);
int atoi(char c);
int htoi(char s[]);
void main() {
printf("%d\n", htoi("62Fa"));
}
@giorgi568
giorgi568 / comrem.c
Created July 29, 2024 18:06
the c programming language exercise 1-23
#include <stdio.h>
#define ARRLEN 1000
#define IN 1 /* in a comment */
#define OUT 0 /* out of a comment */
/* removes comments from c program(only /* style commnets) */
int get_line(char s[], int lim);
int get_line(char s[], int lim)
{
@giorgi568
giorgi568 / entab.c
Created July 29, 2024 18:05
the c programming language exercise 1-21
#include <stdio.h>
#define TABLEN 4
#define ARRLEN 1000
int get_line(char s[], int lim);
/* program for replacing tabs with appropriate number of
blank characters */