mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
Userland: Add a simple /bin/tr program.
This commit is contained in:
parent
671dee9afa
commit
c392c0d799
1 changed files with 28 additions and 0 deletions
28
Userland/tr.cpp
Normal file
28
Userland/tr.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#include <AK/QuickSort.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
|
#include <AK/AKString.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc != 3) {
|
||||||
|
printf("usage: tr <from> <to>");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char from = argv[1][0];
|
||||||
|
char to = argv[2][0];
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
char ch = fgetc(stdin);
|
||||||
|
if (feof(stdin))
|
||||||
|
break;
|
||||||
|
if (ch == from)
|
||||||
|
putchar(to);
|
||||||
|
else
|
||||||
|
putchar(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue