Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program: malloc, free, pointer, function in C main char str[] = this is a test only just a test; /* or other string */ char

Program: malloc, free, pointer, function in C

main

char str[] = this is a test only just a test; /* or other string */

char *ptr1[100], *ptr2[100];

call function1; call function2;

Function1: tokenize the string strwith a pointer, and record each token (NULL terminated) in ptr1 array (i.e., skip white spaces in str)

ptr1[0] = this; ptr1[1] = is; ptr1[2] = a, etc

Function2:

Loop: print ptr1[i] that points to valid word

Loop: for each ptr2[i], malloc and copy the string from ptr1[i], print ptr2[i]

Error handling: copy string only if malloc is successful

Loop: print the pointer value (starting addrof token) of ptr1[i] and ptr2[i]ptr1[i] and ptr2[i] should have different values

Loop: free each of ptr2[i]

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

=+14.4. 1 Let C be the set of continuity points of F.

Answered: 1 week ago

Question

A 300N F 30% d 2 m Answered: 1 week ago

Answered: 1 week ago