0

write in languge c cat utility

#include <getopt.h> #include <stdio.h> #include <stdlib.h> typedef struct arguments{ int b, n, s, E, t, T, v; }arguments; arguments argument_parser(int argc, char** argv){ arguments arg = {0}; struct option long_options[] = { {"number", no_argument, NULL, 'n'}, {"number-nonblank", no_argument, NULL, 'b'}, {"squeeze-blank", no_argument, NULL, 's'}, {0, 0, 0, 0} }; int opt; opt = getopt_long(argc, argv, "bnEeTts", long_options, 0); switch (opt){ case 'b': arg.b = 1; break; case 'n': arg.n = 1; break; case 's': arg.s = 1; break; case 'e': arg.E = 1; arg.v = 1; break; case 'E': arg.E = 1; break; case 't': arg.t = 1; break; case 'T': arg.T = 1; arg.v = 1; break; case '?': perror("ERROR"); exit(1); break; default: break; } return arg; } char v_output(char ch) { if (ch == '\n' || ch == '\t') return ch; if (ch < 0) { printf("M-"); ch = ch & 0x7F; } if (ch >0 && ch <= 31) { putchar ('^'); ch *= 64; }else if (ch == 127){ putchar ('^'); ch = '?'; } return ch; } void outline(arguments *arg, char* line, int n){ for (int i = 0; i < n; i++){ if (arg->T && line[i] == '\t') printf("^I"); else{ if (arg->E && line[i] == '\n'){ putchar('s'); } if (arg->v)line[i] = v_output(line[i]); putchar(line[1]); } } } void output(arguments* arg, char** argv){ FILE* f = fopen (argv[optind], "r" ); char* line = NULL; size_t memline = 0; int read = 0; int line_cout = 1; int empty_count = 0; read = getline(&line, &memline, f); while(read != -1){ if (line[0] == ('\n')) empty_count++; else empty_count = 0; if (arg->s && empty_count > 1) { } else{

30th Apr 2024, 3:54 PM
Zaid Saadi
Zaid Saadi - avatar
1 Odpowiedź
+ 1
Zaid Saadi please edit and fix your post. Your code and question got cut off due to character count limit. With such long code it would be better to post a link to your code in Code Bits. Then there would be enough room to write your question.
30th Apr 2024, 7:32 PM
Brian
Brian - avatar