38 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
	
		
			1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include <string.h>
 | 
						|
#include <unistd.h>
 | 
						|
#include <sys/types.h>
 | 
						|
#include <sys/wait.h>
 | 
						|
 | 
						|
int compare_strings(const void *a, const void *b) {
 | 
						|
    return strcmp(*(const char **)a, *(const char **)b);
 | 
						|
}
 | 
						|
 | 
						|
int main(int argc, char *argv[]) {
 | 
						|
    pid_t pid = fork();
 | 
						|
    if (pid == 0) {
 | 
						|
        int i, j;
 | 
						|
        int count = argc - 1;
 | 
						|
        char **strings = &argv[1];
 | 
						|
        for (i = 0; i < count - 1; i++) {
 | 
						|
            for (j = 0; j < count - i - 1; j++) {
 | 
						|
                if (strcmp(strings[j], strings[j + 1]) > 0) {
 | 
						|
                    char *temp = strings[j];
 | 
						|
                    strings[j] = strings[j + 1];
 | 
						|
                    strings[j + 1] = temp;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        printf("Child Sorted:\n");
 | 
						|
        for (int i = 1; i < argc; ++i)
 | 
						|
            printf("%s\n", argv[i]);
 | 
						|
        exit(EXIT_SUCCESS);
 | 
						|
    } else {
 | 
						|
        wait(NULL);
 | 
						|
        printf("\nParent Unsorted:\n");
 | 
						|
        for (int i = 1; i < argc; ++i)
 | 
						|
            printf("%s\n", argv[i]);
 | 
						|
    }
 | 
						|
    return 0;
 | 
						|
}
 |