In: Computer Science
Question 3. In the following code, answer these questions:
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int changed = 0;
char buff[8];
while (changed == 0){
gets(buff);
if (changed !=0){
break;}
else{
printf("Enter again: ");
continue;
}
}
printf("the 'changed' variable is modified\n %d", changed);
}
END of the questions
:::::::::::::::::::::::::: ::::::::::::::::::::::::::
Submission
For this assignment, you need to write a report file of your work. The report should answer each question in details, providing outputs of the code to justify your answer.
a) initally the variable changed is assigned with 0 and is never updated later on in the code.
so the while loop loops forever(infinitely) taking the input into the char array (string) buff every time the loops runs
---> Here gets() is used so the function takes even the string of length greater than 8 but only the first 8 getting stored in the char array buff and remained buffer overflowed
the compiler throws a warning because of gets and it is not secure to use gets instead we could use fgets in which we will be specifing the length of the input string
b)there no way to know whether the string has been modified or not because we are not outputting the string