Question

In: Computer Science

Please answer the problem below in C programming language: Create a pointer activity source file -...

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).

  1. Create variables for a character, an integer, a string pointer. Based on integer value you will use that number of string pointers.
  2. The string variable is a string pointer that has not been allocated.   
  3. Define pointers to those variables types without any initialization of those points to the previous variables e.g. pChr, pInt, pSentence.
  4. Ensure the argument entered is from 1-3 and the sentence are entered. Errors out if not.
  5. Assign: [using argc and argv]
    1. Integer - to number entered from 1-3
    2. Character - to first letter in the sentence.
    3. String pointer(s) - to sentence(s)
  6. Assign pointers to the corresponding variables.
  7. Call a Function on a separate file - pointPrint.c - passing the initialized pointers. Print out values for the three variables without using the variables themselves as you passed the pointers. Make sure the function also decrements the counter passed by the integer pointer.
  8. Repeat as many times as the argument provided.

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

Solutions

Expert Solution

/*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*/


Related Solutions

Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing...
C Programming Language (Code With C Programming Language) Problem Title : Which Pawn? Jojo is playing chess himself to practice his abilities. The chess that Jojo played was N × N. When Jojo was practicing, Jojo suddenly saw a position on his chessboard that was so interesting that Jojo tried to put the pieces of Rook, Bishop and Knight in that position. Every time he put a piece, Jojo counts how many other pieces on the chessboard can be captured...
In C Programming Language Write a program to output to a text log file a new...
In C Programming Language Write a program to output to a text log file a new line starting with day time date followed by the message "SUCCESSFUL". Please screenshot the results.
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a...
PROGRAMMING LANGUAGE : JAVA Problem specification. In this assignment, you will create a simulation for a CPU scheduler. The number of CPU’s and the list of processes and their info will be read from a text file. The output, of your simulator will display the execution of the processes on the different available CPU’s. The simulator should also display: -   The given info of each process -   CPU utilization - The average wait time - Turnaround time for each process...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language...
Create a CodeBlocks project with a main.cpp file. Submit the main.cpp file in Canvas. C++ Language A Game store sells many types of gaming consoles. The console brands are Xbox, Nintendo, PlayStation. A console can have either 16 or 8 gigabytes of memory. Use can choose the shipping method as either Regular (Cost it $5) or Expedite (Cost is $10) The price list is given as follows: Memory size/Brand Xbox Nintendo PlayStation 16 gigabytes 499.99 469.99 409.99 8 gigabytes 419.99...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences...
please answer with coding from The second edition C programming language textbook /* Changes all occurrences of t in s to u, result stored in v * * Example: * * char v[100]; * replace("hello", "el", "abc", v) => v becomes "habclo" * replace("", "el", "abc", v) => v becomes "" (no change) * replace("hello", "abc", "def", v) => v becomes "hello" (no change) * replace("utilities", "ti", "def", v) => v becomes "udeflidefes" * */ void replace(char *s, char *t,...
Using C Programming. Put all of these 4 things in one source file and attach to...
Using C Programming. Put all of these 4 things in one source file and attach to this question. Put #1 in main. Put all the others into separate function functions but in the same file.   1)   Put this code in main. You are writing a program for Bowl Me Over, a local bowling alley. The program will allow staff to enter any number of bowling scores. Scores in a standard game range between 0 to 300, with being a perfect...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the...
C Language NO ARRAY UTILIZATION OR SORTING Create a .txt file with 20 integers in the range of 0 to 100. There may be repeats. The numbers must not be ordered/sorted. The task is to find and print the two smallest numbers. You must accomplish this task without sorting the file and without using arrays for any purpose. It is possible that the smallest numbers are repeated – you should print the number of occurrences of the two smallest numbers....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT