Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include <locale.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5.  
  6. int pozition(char *string_1, char *string_2)
  7. {
  8.     setlocale(LC_ALL, "Russian");
  9.     int i, j, k, prove=0;
  10.     int length_1, length_2;
  11.    
  12.     printf("\n");
  13.     for(length_1=0; *(string_1+length_1)!='\0'; length_1++);
  14.     for(length_2=0; *(string_2+length_2)!='\0'; length_2++);
  15.     printf("  Длинны строк в порядке ввода : %d, %d\n", length_1, length_2);
  16.     for(i=0; i<length_1; i++){
  17.         if(*(string_1+i)==' ')continue;
  18.         for(j=0; j<length_2; j++){
  19.             for(k=0; k<i; k++){
  20.                     if(*(string_1+i)==*(string_1+k)){k=0; break;}
  21.             }
  22.             if(*(string_1+i)==*(string_2+j) && k!=0){
  23.             prove=1;
  24.             printf("\tПозиця первой встречи с символом '%c' = %d\n", *(string_1+i), j+1);
  25.             break;
  26.     }}}
  27.     if(prove==0) return -1;
  28.     else return 0;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34.     setlocale(LC_ALL, "Russian");
  35.     char *string_1, *string_2;
  36.     int result_of_function;
  37.    
  38.     if(!(string_1=(char*)malloc(256))){
  39.         printf("Недостаточно памяти!");
  40.         return 0;
  41.     }
  42.     if(!(string_2=(char*)malloc(256))){
  43.         printf("Недостаточно памяти!");
  44.         free(string_1);
  45.         return 0;
  46.     }
  47.     printf("Введите строку 1 : "); gets(string_1);
  48.     printf("Введите строку 2 : "); gets(string_2);
  49.     result_of_function=pozition(string_1, string_2);
  50.     printf("\n\n Результат функции : %d", result_of_function);
  51.     getchar(); getchar();
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement