-
Notifications
You must be signed in to change notification settings - Fork 205
/
Copy pathpg271_q012.c
20 lines (19 loc) · 1.08 KB
/
pg271_q012.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
int main (int argc, char* argv[] ){
/* Write an implementation of strncpy using while loop.
* Your program reads a int on a line by itself. This is the max number of chars to copy.
* Followed by a string on a line by itself, terminated by \n
* and calls a function that copies this string into destination string. The destination string is passed as a parameter by calling function
* Function should return pointer to destination string
* Function is expected to copy all chars until \0.
* Buffer overflow check is not expected.
* At most n chars should be copied where n was the number input by user
* Returned string is printed by the calling function
* Assume max string size of 32 chars including \0
* Include error checks for n, 0<n<32
* If input value was outside this range then skip the call to strncpy function and print -1
* Note that input string would still be read in this case
* Do not use strncpy library function
* If source string had less than n chars then simply copy up to terminating \0 */
return 0;
}