Advertisement
Pavle_nis

C COMPARE N CHARACTERS OF STRINGS

Mar 23rd, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. // Uporedjivanje stringova.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdio.h>
  6.  
  7. #ifndef __boolean
  8. typedef unsigned char bool;
  9. static const bool False = 0;
  10. static const bool True = 1;
  11. #endif
  12.  
  13. int main()
  14. {
  15.     char s1[80], s2[80];
  16.     int n1;
  17.     bool isti = True;
  18.     printf("Unesi dva stringa :\n");
  19.     gets(s1);
  20.     gets(s2);
  21.     pocetak:
  22.     printf("Unesi broj karaktera za uporedjivanje: \n");
  23.     scanf("%d", &n1);
  24.     if (n1 > strlen(s1) || n1 > strlen(s2))
  25.     {
  26.         printf("Uneti broj je veci od duzine stringa\n\n");
  27.         goto pocetak;
  28.     }
  29.     for (int i = 0; i < n1; i++)
  30.     {
  31.         if (s1[i] == s2[i])
  32.         {
  33.             isti = True;
  34.             continue;
  35.         }
  36.         else
  37.         {
  38.             isti = False;
  39.             break;
  40.         }
  41.     }
  42.     if (isti)
  43.         printf("Isti!\n");
  44.     else
  45.         printf("Razliciti!\n");
  46.     system("pause");
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement