Advertisement
balsa0

Javított

Apr 15th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. /* 6.6.10 by ShuffleSource
  2.  * Megj: Ezt a kódot magamtól írtam, nem netről kukáztam!
  3.  */
  4.  
  5. //#include <stdio.h>
  6. #include <iostream>
  7.  
  8. //karakterláncok hossza
  9. size_t strlen(const char* p){
  10.     int count = 1;
  11.     while(*p++ && count++);
  12.     return count-1;
  13. }
  14.  
  15. //karakterláncok összehasonlítása
  16. int strcmp(char* s1, char* s2){
  17.     while(!(*s1++^*s2++))
  18.         if (!*s2 || !*s1)
  19.             return !(*s1^*s2);
  20.     return 0;
  21. }
  22.  
  23. char* strcpy(char* dest, char* src){
  24.     int j = 0;
  25.     while( (*src++=*dest++) && (j++)+1 );
  26.     for (int i=strlen(src)-j;i < strlen(dest);i++)
  27.         dest[i] = '\0';
  28.     return dest;
  29. }
  30.  
  31. int main(){
  32.  
  33.     char a[] = "alma";
  34.  
  35.     if (strcmp (a, a))
  36.     std::cout << "1- strcmp nem nulla" << std::endl;
  37.  
  38.     if (!strcmp (a, a))
  39.     std::cout << "1- strcmp nulla" << std::endl;
  40.  
  41.     if (strcmp (a, a) == true)
  42.     std::cout << "1- ShuffleSource" << std::endl;
  43.  
  44.     char b[] = "korte";
  45.  
  46.     if (strcmp (a, b))
  47.     std::cout << "2- strcmp nem nulla" << std::endl;
  48.  
  49.     if (!strcmp (a, b))
  50.     std::cout << "2- strcmp nulla" << std::endl;
  51.  
  52.     if (strcmp (a, b) != true)
  53.     std::cout << "2- ShuffleSource" << std::endl;
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement