Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <stdint.h>
- char st[500];
- void getword() {
- int s = scanf("%s", st);
- if (s == 1) {
- pid_t pid = fork();
- if (pid == 0) {
- getword();
- }
- else {
- int status;
- waitpid(pid, &status, 0);
- int exit_code = WEXITSTATUS(status);
- exit(exit_code + 1);
- }
- }
- else {
- exit(0);
- }
- }
- int main(int argc, char* argv[]) {
- int result;
- pid_t pid = fork();
- if (pid == 0) {
- getword();
- }
- else {
- int status;
- waitpid(pid, &status, 0);
- result = (uint8_t) WEXITSTATUS(status);
- }
- printf("%d\n", result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement