Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ackit -reverse strings
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- char house[]=" t his is a test string";
- //string test a is his t //
- int main(){
- int len = strlen(house);
- char *buff = (char*)malloc(len+1);
- memset(buff,'\0',len * sizeof(char)+1);
- char* end = (house+len);
- char* beg = end;
- int j = 0;
- for(int i = 0; i < len+1; i++){
- beg--;
- if(*beg == ' ' || beg < house){
- char* tmp = beg;
- tmp++;
- while(tmp != end){
- buff[j++] = *tmp++;
- }
- buff[j++]=' ';
- end = beg;
- }
- }
- buff[len+1]='\0';
- printf("%s\n",buff);
- return 0;
- }
Add Comment
Please, Sign In to add comment