Question: below is the file mem.c -------------------------------------------------------------------------------------------------------------------------- #include #include #include #include common.h int main( int argc, char *argv[]) { if (argc != 2) { fprintf(stderr, usage:
below is the file mem.c
--------------------------------------------------------------------------------------------------------------------------
#include
#include
#include
#include "common.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
fprintf(stderr, "usage: mem ");
exit(1);
}
int *p;
p = malloc(sizeof(int));
assert(p != NULL);
printf("(%d) addr pointed to by p: %p ", (int) getpid(), p);
*p = atoi(argv[1]); // assign value to addr stored in p
while (1) {
Spin(1);
*p = *p + 1;
printf("(%d) value of p: %d ", getpid(), *p);
}
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
in mem.c, we noticed the atoi function did not do a good job converting Strings to integers and just returned 0. Write your OWN atoi function that takes as input argv[1] and converts any content to an integer.
Submit your updated mem.c file and a trial run screen shot.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
