From b4350dc1aa94403eeea4f0f7fe9f22c10dda8e2c Mon Sep 17 00:00:00 2001 From: Lloyd Page Date: Wed, 13 Jul 2016 01:44:59 -0400 Subject: [PATCH 1/2] commit assignment8.txt commit filestanddev.c commit float1.txt commit sort.c --- assignment8.txt | 7 +++++ filestanddev.c | 45 +++++++++++++++++++++++++++ float1.txt | 11 +++++++ sort.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 assignment8.txt create mode 100644 filestanddev.c create mode 100644 float1.txt create mode 100644 sort.c diff --git a/assignment8.txt b/assignment8.txt new file mode 100644 index 0000000..bb8d331 --- /dev/null +++ b/assignment8.txt @@ -0,0 +1,7 @@ +Lloyd Page +1. CAN CRASH(potential for infinite while loop) +char value at 129+130+131+"abc" +2. 7 +3. 29(infinite while loop) +4. 29: while((*q++==*b++)!=0) ; + 32: free(p); diff --git a/filestanddev.c b/filestanddev.c new file mode 100644 index 0000000..4eb20d8 --- /dev/null +++ b/filestanddev.c @@ -0,0 +1,45 @@ +/*Lloyd Page*/ +/*reads floats from float1.txt, calculates meand and stand dev of all read in values*/ +#include +#include +#include +float avg(float[],int); +float stddev(float[],float,int); +int main() +{ + int x; + char handler[100]; + FILE *f=fopen("float1.txt","r"); + fgets(handler,sizeof(handler),f); + x=atoi(handler); + float num[x]; + for(int i=0;i +#include +#include +void insertUp(int*,int); +void insertDn(int*,int); +int main() +{ + srand(time(NULL)); + int size; + printf("Enter the size of the array\n"); + scanf("%d",&size); + int *a=(int*)malloc(size*4); + for(int i=0;i-1;i--) + { + for(int j=i;j>-1;j--) + { + if(*(n+i)<*(n+j)) + { + int temp=*(n+i); + *(n+i)=*(n+j); + *(n+j)=temp; + } + } + } +} From fbf52b802109db5b50d55a208c9516c424e7d5c4 Mon Sep 17 00:00:00 2001 From: Lloyd Page Date: Wed, 13 Jul 2016 01:56:50 -0400 Subject: [PATCH 2/2] commit sort.c --- sort.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sort.c b/sort.c index 4c20e5e..249e6fa 100644 --- a/sort.c +++ b/sort.c @@ -4,14 +4,30 @@ #include #include #include +#include void insertUp(int*,int); void insertDn(int*,int); int main() { srand(time(NULL)); int size; - printf("Enter the size of the array\n"); - scanf("%d",&size); + while(1) + { + int N=3; + char *line=malloc(N); + printf("Enter the size of the array\n"); + fgets(line,N,stdin); + size_t last=strlen(line); + while(line[last-1]!='\n') + { + N*=2; + line=realloc(line,N); + fgets(line+last,N/2,stdin); + last=strlen(line); + } + if(sscanf(line,"%d",&size)) + break; + } int *a=(int*)malloc(size*4); for(int i=0;i-1;i--) {