Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
strcopy
#include <stdio.h> #define SIZE 30 //Write a function that copies one string to another and returns the number of //characters copied. int strcopy(const char* source, char* dest) { int i = 0; int stringLength = 0; while (source[i] != 0) { dest[i] = source[i]; i++; stringLength++; } return stringLength; } int main(void) { // my array for the string char sourceString[SIZE]; char destString[SIZE]; int length; printf("Example program for some string manipulations.\n"); // First read in an input string if (fgets(sourceString, SIZE, stdin)) { //give it an array of characters, maximum size it can accept, where you want to get it from length = strcopy(sourceString, destString); printf("Length of %s is %d \n", sourceString, length); printf("Length of %s is %d ", destString, length); } else { printf("Error reading in the string!\n"); } return 0; }
run
|
edit
|
history
|
help
0
domain.com
C_141126_ArrayMayorMenor01
pseudo hw v1
Check EOF Value
MailingList
readability!
Score
project 5 v0.04
C_141203_PALINDROMO
Struct