Question: C program: Partial program needed to be completed in c programming language. // spiral of integers 0, 1, 2 // command line interface with user

C program:
Partial program needed to be completed in c programming language.
// spiral of integers 0, 1, 2 // command line interface with user
#include#include #include
#define LINELIMIT 30 #define NUMLIMIT LINELIMIT-8
char *comline,*number,*xchars,*ychars, *commaloc; size_t bufsize=LINELIMIT; size_t numsize=NUMLIMIT;
int whereis (int P, int* Xval, int* Yval) // completed { }
int whatsat (int X, int Y) // to be completed { // returns the integer found at coordinates X, Y in the spiral }int main() {
int P, x, y, i, go_on=1, command,N, cindex;
comline=malloc(bufsize*sizeof(char)); number=malloc(numsize*sizeof(char)); xchars=malloc(numsize*sizeof(char)); ychars=malloc(numsize*sizeof(char));
while(go_on) { printf("Command: "); memset(comline,' ',bufsize); getline(&comline,&bufsize,stdin);
if (memcmp(comline,"quit",strlen("quit"))==0) go_on=0; else if (memcmp(comline,"whereis",strlen("whereis"))==0)
{ strcpy(number,comline+strlen("whereis")); N=atoi(number); if (N
i=whereis(N,&x,&y);
printf("%d is at %d,%d ",N,x,y); } } else if (memcmp(comline,"whatsat",strlen("whatsat"))==0)
{
// find comma index = C commaloc=strpbrk(comline,",");
if (commaloc==NULL) printf("comma missing "); else { // overwrite comma with null byte
*commaloc=0; // copy first number to xchars strcpy(xchars,comline+strlen("whatsat")); // copy second number to ychars strcpy(ychars,commaloc+1); // convert strings to numbers x=atoi(xchars); y=atoi(ychars); // find contents of the spiral at x,y i=whatsat(x,y); if (i==-1) printf("co-ordinates out of range ");
else printf("%d is at %d,%d ",i,x,y); }
} else printf("invalid command %s ",comline);
} printf("Goodbye "); }
can be arranged on a 2-dimensional plane in the form of a The non-negative integers 0, 1, 2, 3 rectangular spiral thus 12 (2.2) 13 14 (0,2) 16 15 3 2 10 5 8 Complete the given C program by adding two functions whereis and whatsat defined as follows: can be arranged on a 2-dimensional plane in the form of a The non-negative integers 0, 1, 2, 3 rectangular spiral thus 12 (2.2) 13 14 (0,2) 16 15 3 2 10 5 8 Complete the given C program by adding two functions whereis and whatsat defined as follows
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
