Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <locale.h>
- #include <stdio.h>
- #include <windows.h>
- #include <conio.h>
- int pozition(char *string_1, char *string_2)
- {
- setlocale(LC_ALL, "Russian");
- int i, j, k, prove=0;
- int length_1, length_2;
- printf("\n");
- for(length_1=0; *(string_1+length_1)!='\0'; length_1++);
- for(length_2=0; *(string_2+length_2)!='\0'; length_2++);
- printf(" Длинны строк в порядке ввода : %d, %d\n", length_1, length_2);
- for(i=0; i<length_1; i++){
- if(*(string_1+i)==' ')continue;
- for(j=0; j<length_2; j++){
- for(k=0; k<i; k++){
- if(*(string_1+i)==*(string_1+k)){k=0; break;}
- }
- if(*(string_1+i)==*(string_2+j) && k!=0){
- prove=1;
- printf("\tПозиця первой встречи с символом '%c' = %d\n", *(string_1+i), j+1);
- break;
- }}}
- if(prove==0) return -1;
- else return 0;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- char *string_1, *string_2;
- int result_of_function;
- if(!(string_1=(char*)malloc(256))){
- printf("Недостаточно памяти!");
- return 0;
- }
- if(!(string_2=(char*)malloc(256))){
- printf("Недостаточно памяти!");
- free(string_1);
- return 0;
- }
- printf("Введите строку 1 : "); gets(string_1);
- printf("Введите строку 2 : "); gets(string_2);
- result_of_function=pozition(string_1, string_2);
- printf("\n\n Результат функции : %d", result_of_function);
- getchar(); getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement