Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
strcpy
// Template program for the second problem on list -- strcopy // What happens when the string that you copy doesn't fit in // the destination string's statically allocated space? #include <stdio.h> #define SOURCE_SIZE 30 #define DEST_SIZE 10 // Your strcopy implementation goes here // Right now the function just returns the // source string length int strcopy(const char* source, char* dest) { int i; for (i=0; ; i++) { if (source[i]==0) { return(i); } } } int main(void) { // my array for the string char sourceString[SOURCE_SIZE]; char destString[DEST_SIZE]; int stringLength; printf("Example program for my strcopy implmentation\n"); // First read in an input string if (fgets(sourceString, SOURCE_SIZE, stdin)) { // input has worked, do something with data stringLength = strcopy(sourceString, destString); if (stringLength >= 0) { printf("Read in the string \"%s\", length calculated as %d\n", sourceString, stringLength); printf("Copied version of the string is \"%s\"\n", destString); } else { printf("Error calculating string length!\n"); } } else { printf("Error reading in the string!\n"); } return 0; }
run
|
edit
|
history
|
help
0
20171030_TRIANGULO
edmond@DESKTOP-M2BC2LH
Rotación matriz anti horaria
C/Assembly
Adding sums of two 1-D arrays
2.2 Comparision with Matrix Addition Execution Time
struct
object-oriented C by Henry Kroll III www.thenerdshow.com
B_141205_funciones
HW2A