Quantcast
Channel: C - Codecademy Forums
Viewing all articles
Browse latest Browse all 25

C Programming - String Copier

$
0
0

Hi guys,

I can’t get my head round this program. I’ve spent hours trying get it up and running an I’m still getting errors. Can anyone point in the right direction.

#include<stdio.h> #include<string.h> void copy(char *dst, char *src) { while(*src != '\0'){ // while the last character of src is not terminating character enter loop *dst = *src; // copying values from src to dst src++; // increment by 1 dst++; // increment by 1 } *dst = '\0'; // ending string } int main(){ char srcString[] = "We promptly judged antique ivory buckles for the next prize!"; char dstString = strlen(srcString) + 1; // dstString == length of srcString + terminating character copy(dstString, srcString); // Calling copy function with parameters dstString and srcString printf("%s", dstString); // Printing dstString }

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 25

Trending Articles