Reverse The Words In A String | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Im from India i found ur video's very late...boz semester (final)exams are near but after final i promise i will complete ur c programming playlist....❤🎉😊

durkaperiasamy
Автор

Use strtok() to strcpy() words into an array of strings. Then traverse the array in reverse order. Advantage: easier to implement. (Specious advantage). Disadvantage: cannot process an infinite string.

warplanner
Автор

hey sir ! sorry if it is dumb question but i'm new to programming, so when you said we gonna check whether we reached
the end of the string or not, what if the string doesn't end with a space or dot, so the last word in string will not be detected per eg: "good morning sir" so the word "sir" will not be detected unless the string is like that "good morning sir." or that "good morning sir "

mohamedelamine
Автор

The occurences or frequency of words in a string. Please do it.

madhubabu
Автор

What if there is more than one whitespace between every new word?

Awesomeman
Автор

Great method :
// an alternative method without using a temporary array
// by keeping track of the first and the last index for each word
void reverse_words3(char *string){
bool is_word = false;
int first_index = 0, last_index = 0;
for(int i = 0; string[i]; i++){
if(string[i] != ' ' && string[i] != '.'){
if(!is_word){
first_index = i;
is_word = true;
}
}
else if ((string[i] == ' ' || string[i] == '.')){
if(is_word){
last_index = i-1;
is_word = false;
while(first_index < last_index){
char temp = string[first_index];
string[first_index] = string[last_index];
string[last_index] = temp;
++first_index;
--last_index;
}
}
}
}
}

justcurious
Автор

it could be better if the reverse function which has been defined could reverse the place of the words too.... i mean like : yaw eht si siht... anyway. that was good. tnx

mostafamoradi