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....❤🎉😊
@Dhana2100Ай бұрын
Did You?
@ManikantaSaiTejaMathiАй бұрын
Nice set of programs
@warplanner88528 ай бұрын
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.
@madhubabu3482 Жыл бұрын
The occurences or frequency of words in a string. Please do it.
@PortfolioCourses Жыл бұрын
Is this video what you're looking for Madhu? :-) Video: kzbin.info/www/bejne/kKrHl2ymZruCfbc
@mohamedelamine16402 жыл бұрын
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 "
@PortfolioCourses2 жыл бұрын
That's a great question Mohamed. So it will also stop when we reach the end of the string itself. If you look at the source code here: github.com/portfoliocourses/c-example-code/blob/main/reverse_words.c. Specifically, this part here: for (j = 0; i < len; j++, i++) { if (s[i] == ' ' || s[i] == '.') break; temp[j] = s[i]; } the for loop will stop if s[i] is a period or space, but it will *also* stop if i >= len, as the loop will only continue so long as i < len. And we keep incrementing i in the for loop each time, and we keep writing the word into 'temp'. So it should work fine for the last word whether we have "good morning sir." or "good morning sir".
@mohamedelamine16402 жыл бұрын
@@PortfolioCourses Thank you so much 👌😁
@PortfolioCourses2 жыл бұрын
@@mohamedelamine1640 You're welcome Mohamed! :-D
@justcurious19408 ай бұрын
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; } } } } }
@Awesomeman15782 жыл бұрын
What if there is more than one whitespace between every new word?
@PortfolioCourses2 жыл бұрын
If there is a white space character, the inner for loop will immediately break here: if (s[i] == ' ' || s[i] == '.') break; And then the inner while loop will do nothing, and the outer for loop will advance i by 1. The process will just repeat until we hit the next non-space character, so it should work fine in this case.
@mostafamoradi20513 жыл бұрын
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
@PortfolioCourses3 жыл бұрын
So reverse the entire string? I bet that I can make a video on that too, I'll let you know when I post it. :-D In the meantime I have this video where a string is printed in reverse: kzbin.info/www/bejne/n4i0ZqV9jNKejtk
@PortfolioCourses3 жыл бұрын
OK, here is a video for creating a function that will reverse the entire string: kzbin.info/www/bejne/hqW2eZalqpWKf9U