KvArt

Funkcija za brisanje kljucnih reci iz teksta

Jul 12th, 2022
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. /*Napisati funkciju char** rem_word(char** s,
  2. char* w) koja uklanja sve pojave reči w iz niza
  3. reči s i vraća pokazivač na niz reči iz kojeg su
  4. izbačene pojave reči w.*/
  5.  
  6. #include <stdlib.h>
  7. #include <string.h>
  8. char** rem_word(char** s, char* w) {
  9. if(!w) return s;
  10. char **pos = s, **old_s = s;
  11. while(s && *s) {
  12. if(strcmp(*s, w))
  13. *pos++ = *s;
  14. else free(*s);
  15. s++;
  16. }
  17. if(old_s) {
  18. *pos = *s; //NULL
  19. old_s = realloc(old_s,
  20. sizeof(*old_s) * (pos - old_s + 1));
  21. }
  22. return old_s;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment