diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5572a94 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +CC = gcc +CFLAGS = -Wall -Wextra -g -std=c99 +TARGET = memory_demo +SOURCE = main.c + +all: $(TARGET) + +$(TARGET): $(SOURCE) + $(CC) $(CFLAGS) -o $(TARGET) $(SOURCE) + +valgrind: $(TARGET) + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET) + +valgrind-simple: $(TARGET) + valgrind --tool=memcheck --leak-check=yes ./$(TARGET) + +clean: + rm -f $(TARGET) + +.PHONY: all debug valgrind valgrind-simple clean + diff --git a/README.md b/README.md index 7ad2d9b..9fec29e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # ParallelPrograming using this rep for assingments -# ParallelPrograming -using this rep for assingments -rator. Stop. + student@itcenter-lab128:~/Desktop/parallel programing$ cat -A Makefile CC = gcc$ diff --git a/main.c b/main.c new file mode 100644 index 0000000..88a04bb --- /dev/null +++ b/main.c @@ -0,0 +1,36 @@ +#include +#include + +int main(int argc, char *argv[]) { + int ipos = 1, ival; + int *iarray = (int *) malloc(10 * sizeof(int)); + + if (iarray == NULL) { + printf("Memory allocation failed!\n"); + return 1; + } + + if (argc == 2) { + ival = atoi(argv[1]); + } + + for (int i = 0; i < 10; i++) { + iarray[i] = ipos; + } + + for (int i = 0; i < 10; i++) { + if (ival == iarray[i]) { + ipos = i; + } + } + + if (ipos != 1) { + printf("Found ival at index %d\n", ipos); + } else { + printf("Value %d not found in array.\n", ival); + } + + free(iarray); + + return 0; +} diff --git a/makefile b/makefile new file mode 100644 index 0000000..f6b62ac --- /dev/null +++ b/makefile @@ -0,0 +1,21 @@ +CC = gcc +CFLAGS = -Wall -Wextra -g -std=c99 +TARGET = memory_demo +SOURCE = main.c + +all: $(TARGET) + +$(TARGET): $(SOURCE) + $(CC) $(CFLAGS) -o $(TARGET) $(SOURCE) + +valgrind: $(TARGET) + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET) + +valgrind-simple: $(TARGET) + valgrind --tool=memcheck --leak-check=yes ./$(TARGET) + +clean: + rm -f $(TARGET) + +.PHONY: all debug valgrind valgrind-simple clean + diff --git a/memory_demo b/memory_demo new file mode 100644 index 0000000..8c37580 Binary files /dev/null and b/memory_demo differ