Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need this in c programming assignment is given and also code is given you just have to code the lines where it says TODO

I need this in c programming

assignment is given and also code is given you just have to

code the lines where it says TODO here

please edit the code that i have given and please send me screenshot of the output as well

please only edit this below code shown. any other form will not work

please do both files as this is part of one single assignment

image text in transcribed

below is the make file:

image text in transcribed

below is the argshift.c

image text in transcribed

#include #include #include

// return the length of a string // For example, // return 0 if s is "" // return 3 if s is "abc" unsigned long my_strlen(char *s) { unsigned long i = 0;

while (*s ++) i ++; return i; }

/* This should shift the 'a' to 'b', 'b' to 'c', ..., 'z' to 'a', as well as the capital letters. Don't shift non-alphabetical characters. */ char shift_char(char x){

}

/** Returns a pointer to a new string which is * a copy of the given string s. */ char* dup_shift(char* s) { }

int main(int argc, char *argv[]) { char input[100]; printf("Enter a string: "); scanf("%[^ ]s", input); char* dups_ptr = dup_shift(input); printf("%s ", dups_ptr); free(dups_ptr); return 0;

}

---

below is the square.c

image text in transcribed

image text in transcribed

#include #include

/* This program should print the sum of the elements * 1^2, 2^2, 3^2, ..., n^2 * where n is an integer provided by the user on the * command line. Hunt down the bugs and squash them! * Seek out the memory leaks and plug them up! */

/* Computes the sum of the first n elements in the array. */ int sum(int n, int* arr) { int i, sum; for(i = 0; i

/* Fills the given array with the values * 1^2, 2^2, 3^2, ..., (n-1)^2, n^2. */ void fillSquares(int n, int* arr) { int i; for(i = 1; i

/* Reads an integer n from arguments, * fills array with squares, and computes * the sum of the squares. Prints out the * sum before freeing all used memory. */ int main(int argc, char* argv[]) { int n, total; int* arr; printf("Enter a number: "); scanf("%d", &n); assert(n > 0); arr = (int*) malloc(n * sizeof *arr);

fillSquares(n, arr); total = sum(n, arr); printf("total: %d ", total); free(arr);

return 0; }

Welcome to Lab 3! Note that a Makefile is provided. Please study the new features introduced in the file Part 1: valgrind. [30 points] Use gdb and valgrind to find and correct all of the bugs in squares.c. You may need to look at the man pages for any library functions used in the code (e.g., atoi)) to understand their function and to ensure they are being used correctly. Describe all of the bugs you identify in a file called ex1-readme. Completely rewriting the program will not be considered a correct solution Part 2: argshift. [70 points] argshift is a program that takes a string as input, and shifts each letter in it forward by one letter (except z, which gets converted back to a). So, "abcz" should turn into "bcda" This includes capital letters, but does not include non-alphabetical characetrs, such as punctuation, spaces and digits. For this, you should implement the following functions char shift char (char c) char* dup shift(char* s) See the source code for more information about what each function should do The memory space allocated for storing the return string should be dynamically allocated from the heap You should allocate the least amount of space that can still hold the result. Your code should not change the string s For this part you may use the standard library functions malloc, calloc, realloc, free and printf to manage dynamic memory allocation/deallocation and print the result After you implement the function strdup-ptr) correctly, your code should work as in the sample runs listed below: $./argshift Enter a string: Ludicrous Speed, Go! Mvejdspvt Tqffe, Hp! You should fix all memory leaks (if any) in the code. It is highly recommended that you look at an ASCII chart when doing this assignment. One may be found by running man aScil # define more variables so it is easier to # again, study the new varabiles and rules CC-gcc CFLAGS=-g -Wall -std=c99 TARGETS-argshift squares make changes all: $ (TARGETS) #Static Pattern Rules $ (TARGETS): % : %"c $ (CC) (CFLAGS) -o e 2 #include 3 #include 4 5 // return the length of a string 6 // For example, 7// return ifs is "m 8// return 3 if s is "abc" 9 unsigned long my_strlen (char *s) unsigned long e while (*s ++) return i 12 14 15 18/ 19 This should shift the 'a' to 'b', 'b' to 'c',.,'z' to a', as well as the capital letters. 20 21 Don't shift non-alphabetical characters. 22 / 23 char shift_char (char x) 24 25 26 27 28/x Returns a pointer to a new string which is 29 a copy of the given string s. / 30 char* dup_shift(char* s) 32 33 int main(int argc, char argv[]) 34 35 char input[100]; 36 printf("Enter a string: ") 37 Scanf("%AIn]s", input); 38 char* dups_ptrdup_shift(input); 39 printf("%s ", dups-ptr) ; 40 free (dups_ptr); 41 42 return : Cargshiftc le squares-c include 2 #include 3 4/This program should print the sum of the elements 112, 22, 3^2, n^2 , 6 where n is an integer provided by the user on the command line. Hunt down the bugs and squash them! 8 Seek out the memory Leaks and plug them up!/ 9 10 /* Computes the sum of the first n elements in the array. 11 int sum (int n, int* arr) int i, sum; 14 for(i -; in; i++) 15 sum(arr+i); 18 / Fills the given array with the values 19 1A2, 242, 342, ..., (n-1)42, nA2.*/ 20 void fillsquares (int n, int* arr) int i 23 for(i 1; in; i++) arr[i] i*i; = 25 26 27/Reads an integer n from arguments, 28 fills array with squares, and computes 29 the sum of the squares. Prints out the sum before freeing all used memory./ 31 int main(int argc, char* argv[i) 34 35 36 37 38 arr (int*) malloc (n sizeof arr); 39 int n, total; int* arr printf("Enter a number: "); scanf("%d", &n); assert (n > ); 38 arr-(int*) malloc (n sizeof arr) 39 41 42 43 fillsquares (n, total -sum(n, printf("total : free(arr); arr); arr); %d ", total); 45 46 47 return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

In which ways would you measure training success? Explain.

Answered: 1 week ago

Question

Evaluate Meyers and Browns approach to career development.

Answered: 1 week ago