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

1. How do we run this code using Ubuntu/Linux? 2.how do we debug all errors?expe

ID: 3895168 • Letter: 1

Question

1. How do we run this code using Ubuntu/Linux? 2.how do we debug all errors?expect at least 5 errors. 3.show the correct code without errors. ×11?] My Corrputer ×11?Ubuntu 64-bit greet.c (-/)-gedit #include-stdio.h> int display1 char*string)iint display(char*string): int display1 (char*string)() int display2 (char*string1)1 char string2; int size,i; size-strlen (string1); string-(char);forfio, testzeitu)o string2[size-i]-string[i]; strtngt Endedded Linux ntf("The originalsting is%s " ,string); char display|(string), display2 (string); string2[size+1]- printf(" l heistring afterward is % ",string2);} ? pri string[] ; tstlajtsste np dispioyatstring).tring): -

Explanation / Answer

SOlution:

Wrong code:

#include <stdio.h>

int display1(char* string);
//1st error is function prototype name is wrong it must be display 2
int display(char* string);
//2nd main method is empty
int main(){
}
//3rd display1 function definition is empty
int display1(char* string){}

int display2(char* string1){
char string2;//string 2 must be a pointer hence it should be char *string2
int size,i;
size=strlen(string1);
string2=(char*)malloc(size+1);
//4th inside for definition , should be replaced by ;
//5th definition of for loop is empty
for(i=0,i<size,i++){
  
}
string2[size-i]=string[i]; //String is undefined it should be string1
printf("The original string is %s ",string); char string[] = "Embedded Linux";
//6th calling display1 function but display1 definition is ot preset so nthing will happen/display
display1(string);
display2(string);
string2[size+1]=' ';//At last it should contain a null character i.e
//7th %s should be written whereas its written as % only
printf("The string afterward is % ",string2);
  
}
Correct code:

#include <stdio.h>
#include<stdlib.h>
#include<string.h>

int display1(char* string);
//1st error is function prototype name is wrong it must be display 2
int display2(char* string);
//2nd main method is empty
int main(){
char string[] = "Embedded Linux";//Initializing a string
display1(string);//Displaying the string on the console
display2(string);//Reversing and displaying the string
}

//Displays the string as it is
int display1(char* string){

printf("The original string is %s ",string);
}

//Displays the string by reversing it
int display2(char* string1){
char *string2;
int size,i;
size=strlen(string1);
string2=(char*)malloc(size+1);

string2[0]=' ';

for(i=0;i<size;i++){
string2[size-i]=string1[i];
}

printf("The string afterward is %s ",string2);


}

Output:

The original string is Embedded Linux
The string afterward is xuniL deddebmE

To run the file in linux:

gcc reverse.c -o reversestring

chmod +x reversestring

./reversestring

where reverse.c is the correct program.

Note:

Before giving negative feedback please discuss the problem in comment section.