overhaul this shit

and i made my first program in C that's remotely useful, so that's good
This commit is contained in:
Elliott Pardee 2015-06-07 04:05:37 -04:00
parent ec504a1863
commit 8213cf927a
4 changed files with 73 additions and 2 deletions

View File

@ -1,2 +1,2 @@
# typeprint
A quick script to print text files as if it was being typed.
A quick program to print text files as if it was being typed.

36
c/typeprint.c Normal file
View File

@ -0,0 +1,36 @@
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
static int
process(char *name, struct timespec *ts)
{
FILE *file = fopen(name, "r");
if (file == 0){
fprintf(stderr, "[err] you either gave me an invalid file, or no file at all");
return -1;
}
int x;
while ((x = fgetc(file)) != EOF) {
printf("%c", x);
nanosleep(ts, NULL);
}
return 0;
}
int
main(int argc, char *argv[])
{
char *argv0;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10 * 1000000;
process(argv[1], &ts);
return 0;
}

36
go/bin.go Normal file
View File

@ -0,0 +1,36 @@
package main
import (
"os"
"io/ioutil"
"fmt"
"time"
)
func processFile(filename string) {
file, err := ioutil.ReadFile(filename)
if err != nil {
panic(err)
}
for _, j := range file {
if string(j) == "\n" {
fmt.Printf("\n")
} else {
fmt.Printf("%c", j)
}
time.Sleep(time.Millisecond * time.Duration(10))
}
}
func main() {
args := os.Args[1:]
if len(args) == 1 {
processFile(args[0])
} else {
fmt.Println("needs a file to process")
}
}

View File

@ -1 +0,0 @@