This commit is contained in:
2025-08-19 03:01:51 +03:00
parent 8b59e98a7b
commit e1b9f50edc
6 changed files with 242 additions and 0 deletions

33
DeitelC/Chapter7/test.c Normal file
View File

@@ -0,0 +1,33 @@
#include <stdio.h>
void copy1 (char * const s1, const char * const s2);
void copy2 (char * s1, const char * s2);
int main(void)
{
char str1[10];
char *str2 = "Hello"; //str2 points a string
copy1(str1, str2);
puts(str1);
char str3[10];
char str4[] = "Goodbye!"; //str4 creates an array containing string
copy2(str3, str4);
puts(str4);
return 0;
}
// array notation
void copy1 (char * const s1, const char * const s2) {
for (size_t i = 0; (s1[i] = s2[i]) != '\0' ; i++) {
;
}
}
// pointer notation
void copy2 (char * s1, const char * s2) {
for (; (*s1 = *s2) != '\0'; ++s1, ++s2) {
;
}
}