Answer:
Check the explanation
Step-by-step explanation:
a)
1) int main(int argc, char *argv){
argv has always been an array of pointer whereby each and every element points to the command line argument that is passed to the program.
int main(int argc, char *argv[]) {
2) passwords = fopen(filePath, "r");
argv[0] always holds the name of the program currently running i.e. itself
So you shouldn't even try not to open a executable file for reading. since doing this will not give error but you won't be able to read the file as it is a binary file.
it is god to always check whether the file was opened successfully or not after opening the file. If file was not opened successfully fopen will return NULL.
passwords = fopen(filePath, "r");
if(passwords == NULL)
{
printf(“\\ Unable to open file”);
return -1;
}
3) execl(shellPath, "shell", NULL);
Before making a call to execl you should close the open file
close(passwords);
b)
1) char itemID[9];
After creating a char array one should always initialize the array as it may contain some garbage value.
char itemID[9] = “”;
2) scanf("%d", &unitsOrdered);
Since unitOrdered represents the quantity, it should always be non zero and non negative
c)
1) char fullName[MAX_LEN];
MAX_LEN should not be zero or negative as it used to define the size.
If ( MAX_LEN <=0 )
{
return error;
}
else
{
char fullName[MAX_LEN]
}
2) strcpy(fullName, firstName);
Before using the string functions you're expected to always make sure that the pointer that you are passing to the functions should not be NULL i.e. the pointers should always pass to certain memory location.
if (firstName && lastName)
{
strcpy(fullName, firstName);
strcat(fullName, " ");
strcat(fullName, lastName);
return fullName;
}
else
{
return error;
}