Write a program that reads a word and then appends the character '-' between the characters.

Example:
Enter a word : antoun
With '-' between each letter : a-n-t-o-u-n


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <string.h>
#include <conio.h>
#define MAX_SIZE		   128

typedef char StringT[MAX_SIZE];

main()
{

	char str1[MAX_SIZE], str2[MAX_SIZE];
	int length, i, j;

	printf("Enter a word : ");
	gets(str1);

	/* INITIALIzATION !!! */
	length = strlen(str1);
	
	/* For each character in str1 from index 0
	   till the before last (index length-1)
	   we copy it to str2 and we put '-' as 
	   upcoming character in str2 */
	j = 0;
	for (i = 0; i < length-1	 ; i++) {
		str2[j] = str1[i];
		j++;
		str2[j] = '-';
		j++;
	}
	/* we copy the last character of str1 to str2 without putting
	   the character '-'  */
	str2[j] = str1[length-1];
	j++;
	str2[j] = '\0';	 /* ATTENTION !!! Do not forget this '\0' */
	
	printf("With '-' between each letter : %s\n", str2);
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Display the elements of a matrix using an iterative function