Пример #1
0
int reverse_sentence(char *s){
    char *begin, *end;

    if(s==NULL)
        return 1;
    /* begin reverse the entire sentence */
    begin=end=s;
    while(*end!='\0'){
        end++;
    }
    end--;
    reverse_word(begin, end);

    /* begin reverse every word in the sentence */
    begin=end=s;
    while(*begin != '\0'){
        if(*begin==' '){
            end=++begin;
        }else if(*end==' ' || *end=='\0'){
            reverse_word(begin, --end);
            begin=++end;
        }else{
            end++;
        }
    }

    return 0;
}
Пример #2
0
static char *reverse_phrase(char *start, char *end)
{
	char *word_start = start, *word_end = NULL;

	while ((word_end = memchr(word_start, ' ', end - word_start)) != NULL) {
		reverse_word(word_start, word_end - 1);
		word_start = word_end + 1;
	}

	reverse_word(word_start, end);
	
	return reverse_word(start, end);
}
Пример #3
0
static char *reverse_phrase(char *start, char *end)
{
        printk(KERN_INFO "Abin, reverse_phrase function called");
	char *word_start = start, *word_end = NULL;

	while ((word_end = memchr(word_start, ' ', end - word_start)) != NULL) {
		reverse_word(word_start, word_end - 1);
		word_start = word_end + 1;
	}

	reverse_word(word_start, end);

	return reverse_word(start, end);
}
Пример #4
0
// 按单词反转字符串
char *reverse_sentence(char *s) {
	char *p = s;
	char *q = s;
	while (*q != '\0') {
		if (*q == ' ') { //查到一个单词
			reverse_word(p, q - 1);
			q++; //指向下一个单词道字符
			p = q;
		} else
			q++;
	}
	reverse_word(p, q - 1); //逆序最后一个单词
	reverse_word(s, q - 1); //整个句子逆序
	return s;
}
Пример #5
0
void reverse(char* string)
{
    int front =0 ;
    int end = 0;
    int strlength;

    while(1)
    {
        //if it reaches the end of the word it must reverse it
        if ((*(string + end) == ' ') || (*(string + end) == '\0'))
        {
            strlength = end - front;
            reverse_word((string + front), strlength);

            if (*(string + end) == '\0')
            {
                break;
            }
            else if (*(string + end) == ' ')
            {
                front = front + strlength + 1;
                end++;
            }
        }
        else
        {
            end++;
        }
    }
}
Пример #6
0
int reverse(char a[])
{ 
	int i,j,k,s=0,e=0,len=0;
	char t;
	for(i=0;a[i]!='\0';i++)//finding length of string
		continue;
	len=i;
	for(i=0;i<len/2;i++)//reversing string
	{
		t=a[i];
		a[i]=a[len-i-1];
		a[len-i-1]=t;
	}
	//printf("%s\n",a); reverse of original string
	s=0;
	for(j=0;a[j];j++)
	{
		if(a[j+1]==' '||a[j+1]=='\0')
		{
		   e=j;
		   reverse_word(a,s,e);//s:starting position of word e:ending position of word
		   s=e+2;
		}
	}
	printf("the given string after reversing by word is:\n");
	printf("\n%s\n",a);
return 0;
}
Пример #7
0
int main(){
    char word[1000];
    int number = 0;

    scanf("%d", &number);
    reverse_word(word, number);
}
Пример #8
0
void reverse_word(char *array, int n){

    if(n>0){
        scanf("%s\n", array);
        reverse_word(array, n-1);
        printf("%s\n", array);
    }
    return;
}
Пример #9
0
	int 
main()
{
	int len = strlen(s);
	reverse_str(s, s+len-1);
	reverse_word(s);
	printf("%s\n", s);

	return 0;
} 
Пример #10
0
uint32_t reverse_doc( uint8_t *mem, uint32_t sz ) {
	uint32_t x, y;
	uint32_t last_known_pos = -1;
	for( x = 0; x < sz && !reverse; x ++ ) {
		for( y = x; y < sz && !IS_WHITE_SPACE(mem[y]); y ++ );
		reverse_word( &mem[x], y - x );
		x += (y - x);
		last_known_pos = x;
	}
	return last_known_pos;
}
Пример #11
0
int main()
{
    char str[100];
    printf("input:  ");
    gets(str);

    reverse_str(str, str + strlen(str) - 1);
    reverse_word(str);

    printf("output : %s\n",str);

    return 0;
}
Пример #12
0
int main(void)
{
    char string[100] = "Bhavya is good";
    char *string1 = string;
    int c = 0;
    while (*(string1++))

    {
        c++;
    }
    reverse_word(string,c);
    printf("The reversed string is: %s\n",string);
    reverse(string);
    printf("The reversed words are: %s\n",string);
    return 0;
}
Пример #13
0
int main()
{
	char buf[128];
	char l[128];
	while(memset(buf, 0, 128), memset(l, 0,128), fgets(buf, 128, stdin) != NULL)
	{
		if(buf[0] != '\n')
		{
			trim_space(buf);
			reverse(buf);
			reverse_word(buf, l);
			printf("reverse:\n%s\n", l);
			
		}
		
	}
	return 0;
}
Пример #14
0
char* reverse_words_in_buff(char **in_string){
	char *string;
	char *word;
	char *word_end;
	char tmp_char;
	int i;
	int len;
	// Reverse string

	string = *in_string;
	fprintf(stderr, "reverse_words_in_buff( %s );\n", string);
	
	fprintf(stderr, "string_start: %c, string_end: %c, string: %s\n", string[0], string[strlen(string)-1],string);
	len =  strlen(*in_string);
	for(i = 0; i < len/2; i++) {
		tmp_char = string[i];
		string[i] = string[len - i - 1];
		string[len - i - 1] = tmp_char;
	}
	fprintf(stderr, "string_start: %c, string_end: %c, string: %s\n", string[0], string[strlen(string)-1],string);

	// Reverse words
	word = 0;
	word = strtok(string, " ");
	while( 0 != reverse_word(word) ){
		word = strtok(0, " ");
	}
	
	string[strlen(string)-1] = '\0';	
	fprintf(stderr, "string_start (%p): %c, string_end (%p): %c, string: \"%s\"\n", string, string[0], &string[strlen(string)-1], string[strlen(string)-1],string);

	fprintf(stderr, "reverse_words_in_buff(): return %s\n", string);
	fprintf(stderr, "reverse_words_in_buff(): return %s\n", *in_string);

	return *in_string;
}
Пример #15
0
int main (int argc, char **argv)
{
  printf ("%s\n", reverse_word ("student am I"));
  
  return 0;
}