In: Computer Science
Please answer the problem below in C programming language:
Create a pointer activity source file - cptr2.c - that takes two arguments, a number from 1 to 3, and a string sentence(s).
Output should look something like:
./cptr2 1 help people in need
Character: h
Integer: 1
String: help people in need
OR
./cptr2 2 "what time is it" "how are you doing"
Character: w
Integer: 2
String: what time is it
Character: h
Integer: 1
String: how are you doing
/*cptr.c
CODE BEGINS HERE*/
#include <stdio.h>
#include <stdlib.h>
#include "pointPrint.c"
int main(int argc, char** argv)
{
if (argc < 2)
{
printf("ERROR (Incorrect
Argument count)\n");
return -1;
}
int num = argv[1][0] - 48;
char c = argv[2][0];
if (num > 3 || num < 1 || argv[1][1])
// Number more than 1 digit or not in limit(1-3)
{
printf("ERROR (Incorrect
Number Entered)\n");
return -1;
}
else if (argc != num + 2)
{
printf("ERROR (Incorrect
Argument count)\n");
return -1;
}
char** strings = malloc(num *
sizeof(char*));
for (int i = 0; i < num; ++i)
strings[i] = argv[i +
2];
while (num)
{
c =
strings[argv[1][0] - 48 - num][0];
func(strings[argv[1][0]
- 48 - num], &num, &c);
}
return 0;
}
/* END CODE*/
/*pointPrint.c
CODE BEGINS HERE*/
#include <string.h>
int func(char* string, int* num, char* c)
{
printf("Character: %c\n", *c);
printf("Integer: %d\n", *num);
printf("String: %s\n", string);
(*num)--;
return *num;
}
/* END CODE*/