Advertisement
DanikKUL

Функция рекурсивно удаляющая первое слово из строки

Jan 20th, 2022
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. // разработать рекурсивную функцию удаления первого слова из строки
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. void delete(char *str){
  7.     static int index;
  8.     static int amount;
  9.     if(str[0] == ' ' || str[0] == '\0'){
  10.         str = realloc(str, amount * sizeof(char));
  11.         return;
  12.     }
  13.     if(str[index] == '\0'){
  14.         index = 0;
  15.         amount++;
  16.     }
  17.     str[index] = str[index + 1];
  18.     index++;
  19.     delete(str);
  20. }
  21.  
  22. int main(){
  23.     char* str = (char*) calloc (100, sizeof(char));
  24.     gets(str);
  25.     puts(str);
  26.     delete(str);
  27.     puts(str);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement