Question: THIS IS ONE SINGLE ASSIGNMENT PLEASE DO BOTH PARTS.(ITS ONE SINGLE LAB) I need this in c programming assignment is given and also code is
THIS IS ONE SINGLE ASSIGNMENT PLEASE DO BOTH PARTS.(ITS ONE SINGLE LAB)
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

below is makefile

below is 2d-random.c


#include #include
double two_d_random(int n) {
//Fill in code below //You are fee to write some other functions this function //Allocate memory for all the integer (x, y) coordinates inside the boundary //Allocate just one memory block //Figure out how to map between (x, y) and the index of the array //We can treat this allocated memory block as an integer array //Write a function for this mapping if needed.
//When deciding which way to go for the next step, generate a random number as follows. //r = rand() % 4; //Treat r = 0, 1, 2, 3 as moving up, right, down and left respectively.
//The random walk should stop once the x coordinate or y coordinate reaches $-n$ or $n$. //The function should return the fraction of the visited $(x, y)$ coordinates inside (not including) the square.
//Do not forget to free the allocated memory block before the function ends.
}
//Do not change the code below int main() { int trials = 1000;
srand(12345); for(int n=1; n
---
below is strfuncs.c




#include #include
//You might need the below function //This function returns the length of a string //It is equivlent to strlen() in string.h
int lenstr(char* s) { int len = 0; while(s[len++] != ''); return len-1; }
/** Appends the src string to the end of the * dest string. Return the resulting string. */
char* strcat(char dest[], char src[]) { //Add your code here
}
/** Searches the haystack string for the needle * substring. Return a pointer to the located * needle substring in the haystack string if * it exists (and the first if there are more * than one), or NULL if the needle is not in * the haystack. */
char* strstr(char haystack[], char needle[]) {
//Add your code here
}
/** Searches for the first occurrence of the * character c in the string s and returns a * pointer to it. If c does not appear in s, * return NULL. */
char* str_chr(char s[], char c) {
//Add your code here
}
/** Returns a pointer to a new string which is * a copy of the given string s. */
char* strdup(char s[]) { //Add your code here
}
/** Returns 1 if the strings s1 and s2 are the * same, returns 0 otherwise. */
int streq(char s1[], char s2[]) { //Add your code here
}
/** Main function. Add code to free allocated memory! * Valgrind should NOT yield any errors once you're done! * DO NOT CHANGE OUTPUTS! JUST ADD CLEAN UP CODE! */ int main(int argc, char** argv) { /* Read strings from program arguments */ if(argc != 3) { printf("usage: ./strfuncs s1 s2 "); return 1; } char* s1 = argv[1]; char* s2 = argv[2]; printf("String 1: %s ", s1); printf("String 2: %s ", s2); /* Check for string equality */ int s1eqs2 = streq(s1, s2); printf("s1=s2? %s ", s1eqs2 ? "yes" : "no"); /* Concatenate s1 to s2 and s2 to s1 */ char* s1s2 = strcat(s1, s2); char* s2s1 = strcat(s2, s1); printf("s1+s2=%s ", s1s2); printf("s2+s1=%s ", s2s1); /* Check for substrings */ char* s1ins2 = strstr(s2, s1); char* s2ins1 = strstr(s1, s2); printf("s1 in s2 -> %s ", s1ins2 == NULL ? "no" : "yes"); printf("s2 in s1 -> %s ", s2ins1 == NULL ? "no" : "yes"); /* Check for character occurence */ char* ains1 = str_chr(s1, 'a'); printf("'a' in s1? %s ", ains1 == NULL ? "no" : "yes"); /* Check duplication of strings */ char* dups1 = strdup(s1); printf("dup(s1)=%s ", dups1); /* Clean up, i.e. free memory! */ //Add your code here
/* Done! */ return 0; }
#define more variables so it is easier to make changes CC-gcc CFLAGS=-g -Wall -std=c39 TARGETS-2d-random strfuncs all: $ (TARGETS) 2d-random: 2d-random.c $ (CC) $ (CFLAGS) -o Se e.c strfuncs: strfuncs.c $ (CC) $ (CFLAGS) -o Se e.c clean: rm -rf *.o *~$ (TARGETS) G 2d-random.cx Finclude
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
