Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
strcpy template
// 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
A_141110_Perfecto
lol
Primo compuesto
Padding Err
Goodone pointer minus void pointer
HeapSort
Spring 2017 Lab 5 v1
assignment5
etapa final de pregunta 2
NOT a String in C - 2