Hello ppl,,
I would like to know the basic diff between sprintf and memcpy tho i know the syntax of each of these functions....I am interested on functional behaviour of both of these,,,thks in advance!
Hello ppl,,
I would like to know the basic diff between sprintf and memcpy tho i know the syntax of each of these functions....I am interested on functional behaviour of both of these,,,thks in advance!
thks for quick reply Elysia!!
Just to get my understanding right i have an eg here...
Code:char abc_ca[10]; char def_ca[15]; memset(abc_ca,0x00,strlen(abc_ca); memset(def_ca,0x00,strlenf(def_ca); sprintf(def_ca, "%s", abc_ca); so in def_ca[10],[11],[12],[13],[14] i would have values '\0' dince we would copy only 10 characters from abc_ca right?
considering the fact that abc_ca is filled with some data for first 10 characters say "ABCDEFGHIJ"
You have some misunderstanding of strings.
I must remind you that you need a buffer of sizeof("BACDEFGHIJ") + 1 to store that string. Furthermore, strlen will only get the length of a string, not the buffer, and if the buffer is unitialized, then using strlen on it is undefined.
In your example, sprintf will copy abc_ca into def_ca, though. But normally you would use strcpy for that. sprintf is more useful for formatting a string, say using numbers and the like.
got it now...thks elysia