Write strcpy
Completed
Write void my_strcpy(char *dest, char *src) that copies characters including the terminating '\0'. Copy each input word and print the copy in upper case.
Input
n, then n words.
Output
n lines.
Example
Input
2 hello World
Output
HELLO WORLD
Editor
C
Hints
Copy until '\0', then write '\0' yourself.
Solution explanation
The caller must make sure dest has room for the whole string.
Show solution
#include <stdio.h>
#include <ctype.h>
void my_strcpy(char *dest, char *src) {
while (*src != '\0') {
*dest = *src;
dest++;
src++;
}
*dest = '\0';
}
int main() {
int n;
char w[100], copy[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", w);
my_strcpy(copy, w);
for (int j = 0; copy[j] != '\0'; j++) copy[j] = toupper(copy[j]);
printf("%s\n", copy);
}
return 0;
}