-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path16_copy_user_def.c
46 lines (34 loc) · 1.07 KB
/
16_copy_user_def.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// // Write a c program to copy one string into another using user-defined function.
// // Header Files
#include <stdio.h>
#include <conio.h>
#include <string.h>
#define ARRAY_SIZE 31
// // Function Declarations
char *copyString(char[], char[]);
// // Main Function Start
int main()
{
char str[ARRAY_SIZE], copyStr[ARRAY_SIZE];
printf("\nEnter Any String to Copy Make Its Copy (MAX CHARACTERS %d) => ", ARRAY_SIZE - 1);
fgets(str, ARRAY_SIZE, stdin); // // Input String
str[strcspn(str, "\n")] = '\0'; // // Replace '\n' character with '\0' in str
copyString(copyStr, str); // // copy str into copyStr using user-defined function
printf("\nOriginal String => %s", str);
printf("\nCopy of Entered String => %s", copyStr);
putch('\n');
getch();
return 0;
}
// // Main Function End
// // Function Definitions 👇👇
// // Function to Copy One String into Another
char *copyString(char des[], char src[])
{
// // Copy str into copy
int i = 0;
for (i = 0; src[i]; i++)
des[i] = src[i];
des[i] = '\0';
return des;
}