first commit
This commit is contained in:
commit
fc4a71d4a9
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
/rot13
|
9
Makefile
Normal file
9
Makefile
Normal file
|
@ -0,0 +1,9 @@
|
|||
CC= tcc
|
||||
CFLAGS= -Wall -Wextra -Werror
|
||||
LDFLAGS= -s
|
||||
|
||||
all: rot13
|
||||
%: %.c
|
||||
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
clean:
|
||||
$(RM) *.o rot13
|
29
rot13.c
Normal file
29
rot13.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include<unistd.h>
|
||||
#include<fcntl.h>
|
||||
int main(int argc,char**argv)
|
||||
{
|
||||
|
||||
int fd=0;
|
||||
|
||||
if(argc>1)
|
||||
{
|
||||
fd=open(argv[1],O_RDONLY);
|
||||
if(fd<0)
|
||||
{
|
||||
write(2,"failed to open file\n",20);
|
||||
fd=0;
|
||||
}
|
||||
}
|
||||
|
||||
int c;
|
||||
while(read(fd,&c,1))
|
||||
{
|
||||
if(c>='a'&&c<='z')
|
||||
c=((c-'a')+13)%26+'a';
|
||||
else if(c>='A'&&c<='Z')
|
||||
c=((c-'A')+13)%26+'A';
|
||||
else if(c>='0'&&c<='9')
|
||||
c=((c-'0')+10)%10+'0';
|
||||
write(1,&c,1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user