Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

nclude int main(void) char *ch *ch-malloc(sizeof(char)*2); ch[ 1 ]=\'3\'; ch[2]

ID: 3872098 • Letter: N

Question

nclude int main(void) char *ch *ch-malloc(sizeof(char)*2); ch[ 1 ]='3'; ch[2] a' while (ch[]> 0) printf("Character: %c and %cin", ch[l], ch[2]); ch[1] printf("main:00pin ch%pin ch-I %pin ch +2%pin "&main;,ch.ch+1.ch+2); return ch[l)]: # include # include #include-malloc.h> int main(void) char *s, "dyn_s; int In; printf"Enter the input string n" scanf("%s",s); In = strlen(s); "dyn s-(char*)malloc(strlen(s)+1) dyn-s-s; dyn-s[strlen(s)] 0'; printfídyn_s); return 0; Please make these programs faults and comment in the code e the changes. work with no errors or seg xpaining why you made

Explanation / Answer

#include<Stdio.h>

#include<malloc.h> \Library is missing

int main(void)
{
char *ch;
*ch=malloc(2*sizeof(char)); \ This is InCorrect syntax of malloc size is *ch=mallocsizeof(char)*2);
ch[1]='3';
ch[2]='a';
while(ch[1]>'0')
{
printf("Character :%c and %c ",ch[1],ch[2]);
ch[1]--;
}
printf("main:%p ch:%p ch+1:%p ch+2:%p",&main,ch,ch+1,ch+2);
return ch[1];
}

______________________________________________________________________________________________

#include<Stdio.h>
#include<string.h>
#include<malloc.h>

Int main(void)
{
char *s,*dyn_s;
Int ln;
Printf("Enter the input string");
scanf("%s", &s); \Ampersand is used before s in scanf function
ln=strlen(s);
*dyn_s=(char*)malloc(strlen(s)+1);
dyn_s=s;
dyn_s[strlen(s)]='';
printf(dyn_s);
return 0;
}