In this tutorial, we are going to write a C program to copy one string into another and count the number of characters copied in C Programming with practical program code and step-by-step full complete explanation.
C Program to count the number of characters copied into a string.
#include<stdio.h> #include<conio.h> void main() { char string1[80], string2[80]; int i; printf("Enter a stringn"); printf("?"); scanf("%s",string2); for(i=0;string2[i]!=' ';i++) string1[i]=string2[i]; string1[i]=' '; printf("n"); printf("%sn",string1); printf("Number of characters=%dn",i); }
Output
Enter a string ? Manchester Manchester Number of characters=10 Enter a string ?westminister Westiminister Number of characters=11