Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Working on a program where my task is to implement a library (as a set of source and header files, documentation, and a Makefile) that

Working on a program where my task is to implement a library (as a set of source and header files, documentation, and a Makefile) that provides a few useful functions for working with a counted string data structure.

And one of the functions that needs to be written is described below but I am having a little difficulty writing it. Program needs to be written in C.

void kstrput(kstring str, size_t pos, char ch)

Replaces the character at index pos in str's data with the character ch.

If pos is out of bounds (greater than or equal to the length of str), this function should abort the program by calling abort()

Here are some other functions that I have already written:

int kstrlen(char kstring[]) // function to return length of string { int j = 0; while (kstring[j] != '\0') //using while loop for reading every character of string //because a string is terminated by a null character { ++j; } return j;

}

int kstrget(char kstring[],int pos) // function to return character at a specific index { int j = 0; while (kstring[j] != '\0') //using while loop for reading every character of string //because a string is terminated by a null character { ++j; } if(pos<=j+1) return kstring[pos-1]; //return character at specific index else abort(); //abort if index is out of bound }

void kstrput(kstring str, size_t pos, char ch) { if(pos>=str.length && pos<0) abort(); else *((str.data)+pos) = ch; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago