#include <stdio.h>
void string_copy(char [], char []); /* function prototype */
int main()
{
char a[100]; /*** source string ***/
char b[100]; /*** destination string ***/
printf("\n Input source string : ");
scanf("%[^\n]",a); /* read input source string */
string_copy(b,a); /* function call */
printf("\n Destination string : %s\n",b);
return 0;
}
/*** function definition ***/
void string_copy(char d[], char s[])
{
int i = 0;
printf("\n Source string : %s\n",s);
/* copying the string */
for (i = 0; s[i] != '\0'; i++)
d[i] = s[i];
d[i] = s[i]; /* Copy NUL character to destination string */
}
Input source string : atnyla
Source string : atnyla
Destination string : atnyla
First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.