The Code-Bin
Links
Home
Add your code!
All Listings
About
Latest Entry
Featured Scripts
Author's Website
Latest Entries
FFMPEG Thumbnail Scr...
PHP, 0.8KB
Jul. 29, 10:24pm
John
Z80 Assembler, 190 bytes
Feb. 17, 3:36am
John
Z80 Assembler, 176 bytes
Sep. 13, 2:19am
John
Z80 Assembler, 77 bytes
Sep. 13, 2:18am
John
Z80 Assembler, 209 bytes
Sep. 13, 2:17am
untitled C Code
Posted by: WankyPanys | March 4, 2010 @ 5:10am
C Code
[
Download
]
#include <stdio.h> #include <string.h> #include <conio.h> void reverse_block(char* p, int start, int len) { int a, b; a = b = 0; for (a = start, b = start+len; a <= b; a++, b--) { char tmp = p[a]; p[a] = p[b]; p[b] = tmp; } } // I like pie // eip ekil I // pie like I void reverse_words(char* p) { // I like pie int len = strlen(p)-1; for (int idx = 0; idx < (len/2); idx++) { char tmp = p[idx]; p[idx] = p[len-idx]; p[len-idx] = tmp; } // eip ekil I int block_start = 0; int block_end = 0; for (int idx = 0; idx <= len+1; idx++) { if (p[idx] == ' ' || p[idx] == '\0') { block_end = idx-1; reverse_block(p, block_start, block_end - block_start); block_start = block_end + 2; } else { continue; } } } int main() { char buf[64]; strcpy(buf, "Here is an example sentence for testing"); printf("%s\n", buf); reverse_words(buf); printf("%s\n", buf); getchar(); return 0; }
Syntax Highlighting
[
Open in new window
]
Author Comments
none
Rating
4.81 / 8
52 Votes
http://codebin.yi.org/528
page generated in 0.01 seconds