Advertisement
2607

Untitled

Sep 28th, 2021
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void input_str();
  5. void printt(char *str, int i);
  6.  
  7.  
  8. int main() {
  9.     input_str();
  10.     /*
  11.     int i = 10;
  12.     for(int j = 0; j < i; j++) {
  13.         printf("%c", str[j]);
  14.     } */
  15.     return 0;
  16. }
  17.  
  18.  
  19. void input_str() {
  20.     char *str = malloc(sizeof(char));
  21.     char c;
  22.     int i;
  23.     while (c!='\n') {
  24.         scanf("%c", &c);
  25.         *(str+i) = c;
  26.         i++;
  27.         char *str = realloc(str, i*sizeof(char));
  28.     }
  29.     printf("%d\n", i-1);
  30.     for(int j = 0; j < i; j++) {
  31.         printf("%c", *(str+j));
  32.     }
  33.     printt(str, i);
  34. }
  35.  
  36. void printt(char *str, int i) {
  37.     for(int j = 0; j < i; j++) {
  38.         printf("%c", *(str+j));
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement