I am trying to print out hello fred and I managed only to print out hello. what change do I need to make to print fred too.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//
// A short program to print the string "Hello, Fred"
//
int main (int argc, const char *argv[])
{
char name[5];
char ch = name[5];
char *last_char = &name[5];
ch = *last_char;
char *src = "Fred";
char *dst;
dst = name;
// copy the name
while (*src)
{
src != 0;
++src;
*dst = *src;
}
char *msg = (char *) malloc (5);
strcpy (msg, "Hello, ");
strcat (msg, name);
puts(msg);
//free (last_char);
free (msg);
*last_char = 'A';
//free (msg);
msg = (char *) malloc (5);
msg = src;
puts (msg);
return 0;
}