Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <string.h>
- using namespace std;
- char* split( char* a, int start, int end)
- {
- char words[12];
- for ( int i = start; i < end; i++)
- {
- words[i-start] = a[i];
- }
- words[end - start] = 0;
- return words;
- }
- //a là chuỗi cần cắt, limit là ký tự phân chia. vd: cắt từ thì limit là ' '
- void reWordsString( char *a, char limit)
- {
- int length = strlen(a);
- int start = 0;
- int end = length;
- char words[12];
- for ( int i = length; i >= -1; i--)
- {
- if ( a[i] == limit || i == -1)
- {
- start = i + 1;
- strcpy(words, split(a, start, end));
- cout << words << ' ';
- end = i;
- }
- }
- }
- int main()
- {
- char *a = "hoc lai tu can ban nhe";
- reWordsString(a, ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement