Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. /*
  2.   Navrhnete funkci
  3.      char *Obrat(char *text);
  4.   Ktera zjisti delku predavaneho textu,
  5.   podle delky si alokuje pomocne pole a do tohoto pole
  6.   zkopiruje predavany text pozpatku. Pak ho zkopiruje zpet do
  7.   parametru text. V main vyzkousejte.
  8. */
  9.  
  10. #include<stdio.h>
  11. #include<conio.h>
  12. #include<stdlib.h>
  13. #include<string.h>
  14.  
  15. char* Obrat(char* text);
  16.  
  17. void main()
  18. {
  19.     char text[100];
  20.  
  21.     printf("Zadejte libovolny text: ");
  22.     gets(text);
  23.        
  24.     text = Obrat(text);
  25.  
  26.     printf("%s",text);
  27.  
  28.     getch();
  29. }
  30.  
  31. char* Obrat(char* text)
  32. {
  33.     int i, size = strlen(text);
  34.     char text2[size + 1];
  35.  
  36.     for(i = 0; i < size; i++)
  37.     {
  38.         text2[i] = text[size - i - 1]; 
  39.     }
  40.  
  41.     text2[i] = 0;
  42.     strcpy(text,text2);
  43.     return text2;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement