From f12ebe606f64d5a5231cd966ab1236203595315c Mon Sep 17 00:00:00 2001 From: Sheqi Date: Wed, 13 Jul 2016 00:31:34 -0400 Subject: [PATCH 1/4] sort --- sort.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 sort.c diff --git a/sort.c b/sort.c new file mode 100644 index 0000000..3c4acb9 --- /dev/null +++ b/sort.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +int main(){ + srand(time(NULL)); + int x; + printf("Please enter an integer:\n"); + char*array1=malloc(x*sizeof(array1)); + fgets(array1,x,stdin); + size_t last=strlen(array1); + + int i,j; + for(i=0;iarray2[b+1]) + { + tem1=array2[b]; + array2[b]=array2[b+1]; + array2[b+1]=tem1; + } + } + } + + int c,d; //www.studystreet.com/program-sort-array-descending-order/ + int tem2; + for(c=0;c Date: Wed, 13 Jul 2016 09:32:31 -0400 Subject: [PATCH 2/4] assignment 8 --- Assignment 8 Sheqi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Assignment 8 Sheqi diff --git a/Assignment 8 Sheqi b/Assignment 8 Sheqi new file mode 100644 index 0000000..7fd22dc --- /dev/null +++ b/Assignment 8 Sheqi @@ -0,0 +1,18 @@ +Assignment 8 Sheqi + +1. What is the output? Assume that the malloc() call was successful. If you think that the program contains bugs (other than memory leaks) that can make the program crash (ex. segmentation fault), write "CAN CRASH" and then write the most likely output if the program happens to run without crashing. +Answer: +The output is "ABCabc123". CAN CRASH. Most likely output: usage: ./a.out . + +2. If the program is run using valgrind, how many bytes will valgrind report as "definitely lost"? You can write 0 if you think there is no memory leak that valgrind will consider "definitely lost". Please make sure to write the number of BYTES. +Answer: +1*2=2. Because only *p is been allocated, while is not freed as well. In this circumstance, only *p is the memory leak. + +3. Identify the line numbers that contains memory errors other than memory leaks (invalid access, for example.) If you think that there is no memory error other than possible memory leaks, write NONE. You don’t have to identify the nature of the memory errors. Just line numbers. +Answer: +None. + +4. Modify the program to fix ALL memory errors, including memory leaks. Write only the lines that need to be fixed. Write the line number and the line of code that will replace that line. If you think there is nothing to fix, write "NO CHANGE". The program can be memory error free by modifying 0 to 3 lines of code. Please do not modify more than 3 lines of code. +35 free(p); +36 return 0; +37} From 96307a9eef574f2dba1bbfe256195adbfaf897ad Mon Sep 17 00:00:00 2001 From: Sheqi Date: Wed, 13 Jul 2016 09:34:17 -0400 Subject: [PATCH 3/4] meanStandardDeviation.c --- meanStandardDeviation.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 meanStandardDeviation.c diff --git a/meanStandardDeviation.c b/meanStandardDeviation.c new file mode 100644 index 0000000..acb66a4 --- /dev/null +++ b/meanStandardDeviation.c @@ -0,0 +1,41 @@ +#include +#include +#include + +int main(){ + FILE*numberFile = fopen("number.txt","r"); + + char number[100]; + fgets(number,sizeof(number),numberFile); + int a,i; + + for(i=0;i Date: Thu, 14 Jul 2016 02:59:09 -0400 Subject: [PATCH 4/4] sorting --- sort.c | 75 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/sort.c b/sort.c index 3c4acb9..6e1592d 100644 --- a/sort.c +++ b/sort.c @@ -5,46 +5,52 @@ int main(){ srand(time(NULL)); - int x; printf("Please enter an integer:\n"); - char*array1=malloc(x*sizeof(array1)); - fgets(array1,x,stdin); - size_t last=strlen(array1); + int x; + scanf("%d",&x); + int array1[x]; + int*p=array1; + p=(int*) malloc (100); - int i,j; + int i; for(i=0;iarray2[b+1]) + if(array2[j]>array2[j+1]) { - tem1=array2[b]; - array2[b]=array2[b+1]; - array2[b+1]=tem1; + tem1=array2[j]; + array2[j]=array2[j+1]; + array2[j+1]=tem1; } } } - int c,d; //www.studystreet.com/program-sort-array-descending-order/ - int tem2; - for(c=0;c