Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h> // for output
- #include <string.h> // string functions
- #include <stdlib.h> // standard library
- // In C, strings are stored as character codes ( ASCII or Unicode )
- // and have a 0 at the end
- int main () // execution starts here
- {
- char * str = "ABCDEFG"; // string in memory. Has 0 at end
- const int BUFSIZE=256; // size of buffer = 256 bytes
- char * buffer = malloc(BUFSIZE); // get memory block of this size
- for (int i=strlen(str); i>0; i--) // for loop. i decrease from string length to 0
- {
- memset(buffer, 0,BUFSIZE); // fill buffer with zero
- strncpy(buffer,str, i); // copy i bytes from str to buffer
- printf("%s\n", buffer); // print buffer
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment