#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include<string.h>
int main(void) {
int i,count=1,len=5,j,value,k;
// Allocate memory of size 5
char **array1 = malloc(len * sizeof(char *));
//another array for reallocation
char **array2;
size_t size = 10;
ssize_t nread;
for(i=0;i<len;i++){
array1[i] = malloc(3* sizeof(char));
// Adjusts the size of array[i] automatically
printf("\n String");
nread = getline(&array1[i],&size,stdin);
count++;
if(count == len){
//new array of size double of the original array
array2 = (char **)realloc(array1, sizeof(char *) * 2*len);
for(i=len-1;i<(2*len);i++){
array2[i] = malloc(3* sizeof(char));
// Adjusts the size of array[i] automatically
printf("\n String");
nread = getline(&array2[i],&size,stdin);
count++;}
len = 2*len;
}
}
//printf("\n %d",count);
value = count-1;
//delete adjacent duplicate values
for(i = 0; i < value; i++)
{
for(j = i+1; j < value; )
{
if(strcmp(array2[j],array2[i])==0)
{
for(k = j; k < value; k++)
{
strcpy(array2[k],array2[k+1]);
}
value--;
}
else
{
j++;
}
}
}
for(i = 0; i < value; i++)
printf("Your string: %s\n", array2[i]);
return 0;
}
Implement a C program unique.c that recreates the functionality of the uniq tool by reading the...
I have some questions about pointers/pointer arithmetic in C++ 1) Pointers and Pointer Arithmetic a.) What is the difference between statically allocated arrays and dynamically allocated arrays (be brief) b.) Which of the following pointers can be used for a dynamically allocated array? (Circle) char ptr; char * ptr; char ptr *; char ptr[]; char [] ptr; c.) Show now, using that pointer, how to dynamically allocate array of characters of size 10: (don't use malloc) d.) Which of the...
Write a C++ program that will test function described below that use pointers and dynamic memory allocation. Functions: You will write the function described below. Then you will call them from the main function, to demonstrate their correctness. concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then...
Create a C program to implement a grade book. Must follow these guidelines: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the comand line an integer n (<= 30) as the number of students in the class. You may assume that the input will always be valid. 4. Dynamically allocate memory for an array of...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
(C++ programming) Need help with homework. Write a program that can be used to gather statistical data about the number of hours per week college students play video games. The program should perform the following steps: 1). Read data from the input file into a dynamically allocated array. The first number in the input file, n, represents the number of students that were surveyed. First read this number then use it to dynamically allocate an array of n integers. On...
Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX_NAME_LENGTH]; int customer_number[N_CUSTOMERS] A program uses a text file that contains the following data on each line: The customer number is an int, and the first and last names are alphabetic strings that contain no whitespace. The last and first names themselves are however separated by whitespace. Write a C function with the following prototype: void read_customer (char name[][MAX_NAME_LENGTH], int number[], int position, FILE *cust_file) Your function should read a...
In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...
How would I change the following C code to implement the following functions: CODE: #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]) { if (argc != 2) printf("Invalid input!\n"); else { FILE * f = fopen (argv[1], "r"); if (f != NULL) { printf("File opened successfully.\n"); char line[256]; while (fgets(line, sizeof(line), f)) { printf("%s", line); } fclose(f); } else { printf("File cannot be opened!"); } } return 0; } QUESTION: Add a function that uses fscanf like this:...
C
program
Main topics: Files Program Specification: For this assignment, you need only write a single-file C program. Your program will: Define the following C structure sample typedef struct int sarray size; the number of elements in this sanple's array floatsarray the sample's array of values sample Each sample holds a variable number of values, all taken together constitute a Sample Point Write a separate function to Read a file of delimited Sample Points into an array of pointers to...
C programming Strictly -
Write a program to sort an array of
integers via arrays of pointers to those integers as shown in the
figure.
Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...