When I run this c snippet, it outputs something really random every time, and then segfaults... Code:
#include <stdio.h>
#include <stdlib.h>
int parse(void) {
int i = 0;
int system(const char *command);
char line[1024];
scanf("%[^\n]", line);
system(line);
do {
line[i] = "\0";
i++;
} while (i != 1024);
parse();
}
int main(void) {
parse();
return 0;
}
What I expected was a prompt, and when any shell command is entered (I used pwd for my testing), the output of the command prints and the prompt returns. And this is what actually happened:
Output:
> pwd
/home/runner/c-test
sh: 1: �: not found
sh: 1: : not found
sh: 1: ׀: not found
signal: segmentation fault (core dumped)