summaryrefslogtreecommitdiffstats
path: root/5/11.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2022-01-22 15:18:11 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2022-01-22 15:18:11 +0800
commite7a644113ff0b05332dc1a94ee843fc67b683944 (patch)
tree4a6967637d0d83f94b5a745d12c7e024849ae72f /5/11.c
parentea5d3be32de1acb35a95d8043c81dafc033e3474 (diff)
downloadk&r-exercises-e7a644113ff0b05332dc1a94ee843fc67b683944.tar.gz
5.11
Diffstat (limited to '5/11.c')
-rw-r--r--5/11.c60
1 files changed, 16 insertions, 44 deletions
diff --git a/5/11.c b/5/11.c
index 0399526..75d1389 100644
--- a/5/11.c
+++ b/5/11.c
@@ -1,55 +1,27 @@
#include <stdio.h>
#include <stdlib.h>
-#define TABSIZE 8
-#define MAXLEN 1000
-#define COLCOUNT 100
-
void entab(char *s, char *t, int *tablist, int tablistc);
int main(int argc, char *argv[]) {
- int colsize;
- int tablistc, *tablist, *tablistp;
- char *s, *col, *colp, *colstr;
-
- s = malloc(sizeof(char) * MAXLEN);
- col = malloc(sizeof(char) * MAXLEN);
- colp = col;
+ char op;
- if (argc < 2) {
- tablist = malloc(sizeof(int));
- tablist[0] = 8;
- } else {
- tablist = malloc(sizeof(int) * COLCOUNT);
- tablistp = tablist;
- for (colstr = argv[1], tablistc = 0; *colstr != 0; colstr++) {
- if (*colstr == '"')
- continue;
- if (*colstr == ',' || *colstr == ' ') {
- tablistc++;
- if (tablistc != 1 && tablistc % COLCOUNT == 1) {
- tablist = realloc(tablist, sizeof(int) * COLCOUNT);
- if (tablist == NULL) {
- printf("error: realloc\n");
- free(tablist);
- return 1;
- }
- }
- *colp++ = 0;
- colp = col;
- *tablistp = atoi(col);
- tablistp++;
- } else {
- // todo: realloc based on colc
- *colp++ = *colstr;
- }
- }
+ if ((argc != 2 && argc != 3) || (op = argv[1][1] != 'e' && op != 'd')) {
+ printf("Usage: -e 5,3...\n");
+ return 1;
}
- printf("Enter text to entab\n");
- fgets(s, MAXLEN, stdin);
+
- free(s);
- free(col);
- free(tablist);
+ switch (op) {
+ case 'e':
+ // todo: entab
+ break;
+ case 'd':
+ // todo: detab
+ break;
+ default:
+ printf("Error: invalid operation.\n");
+ return 1;
+ }
} \ No newline at end of file