// Nov. 23, 2026 malloc and free classroom activity
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// #defines and function prototypes normally go in header files
#define MAX_BUFFER (19)

// Concept: Library routines that accept a string of characters.
// 			make a copy of that string
//			that we count the number of a particular letter in that copy
//			print out the count and the selected letter

/*
 Specification
	Use malloc to create the copy of the passed string
	Print the selected letter and the number of occurrences
	Use free to release that memory before exiting

 Design
	malloc_copy function that has one parameter that is the source string
	that we are going to copy and it returns the malloc'ed copy pointer.
	malloc_copy does not have to check for valid source string.
	count function has two parameters -- the malloc copy string and the letter
	include in the count function printing out the letter and its count.

 method functions go here
*/

char *malloc_copy( const char *source_string )
{
	//char *copy = malloc( sizeof( char ) * ( 1 + strlen( source_string ) ) ) ;
	char *copy ;

	strcpy( copy, source_string ) ;

	return copy ;
}

void count( char *copy, char letter )
{
	free( copy ) ;
}

int main( int argc, char *argv[] )
{
	char *copy ;

	copy = malloc_copy( "abc" ) ;

	count( copy, 'b' ) ;

	return 0 ;
}
