|
CS256 - Fundamentals of Structured Programming
| Displaying exercises/e7/solution/p4.c
#include <stdio.h>
#define K 1024
/**
* Copy the string in src to dst. Only copy as many characters (including the
* null character) that are in src to dst. Points will be deducted for copying
* too many or too few characters.
*/
void my_strcpy(char dst[], char src[])
{
int i;
for(i=0; src[i] != '\0'; i++) {
dst[i] = src[i];
}
dst[i] = '\0';
}
int main(void)
{
char input[K+1], copy[K+1];
// Get a line of input (up to K number of bytes) into the 'input' string:
fgets(input, K, stdin);
// Do not modify any of the following:
my_strcpy(copy, input);
printf("%s", copy);
return 0;
}
|