Commit 943a91fb authored by Alec's avatar Alec
Browse files

Works, except with values higher than 9

parent 7523269b
CC=gcc
FLAGS= -Wall -Werror
CFLAGS= -g -std=c99
LDFLAGS= -fsanitize=address -fsanitize=leak
pointer_sort: pointer_sort.o
$(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS) -lm
pointer_sort.o: pointer_sort.c
$(CC) $(FLAGS) $(CFLAGS) $(LDFLAGS) -c $^
clean:
rm -f *.o
rebuild: clean
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
void sort(char** list, int size)
{
for (int i = size; i > 0; i--)
{
for (int y = 0; y < i-1; y++)
{
if (*list[y] > *list[y+1])
{
char tmp = *list[y];
*list[y] = *list[y+1];
*list[y+1] = tmp;
}
}
}
}
void print_list(char** list, int size)
{
for (int i = 0; i < size; i++)
{
printf("%c ", *list[i]);
}
printf("\n---\n");
}
int main(int argc, char *argv[])
{
char** list = argv;
for (int i = 0; i < argc; i++)
{
if (i == argc-1)
{
list[i] = NULL;
break;
}
*list[i] = *list[i+1];
}
print_list(list, argc-1);
sort(list, argc-1);
print_list(list, argc-1);
return 0;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment