Skip to content

Instantly share code, notes, and snippets.

@Evshved
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save Evshved/cd8c572d56210352ed85 to your computer and use it in GitHub Desktop.

Select an option

Save Evshved/cd8c572d56210352ed85 to your computer and use it in GitHub Desktop.
Introducing in strings
#include <vcl.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <classes.hpp>
#pragma hdrstop
void addon(void);
void main(void);
void addon (void){
char str[25][81],str_variable[81]="",str_input[81]="";
int counter_string,counter_id_string,n,i,g,k,len_str_input,r;
int char_of_one, char_of_two,max;
clrscr();
printf("Input string\n");
fflush(stdin);
//ввод
gets( str_variable );
strcat(str_input," ");
strcat(str_input,str_variable);
len_str_input=strlen( str_input );
//добавление пробелов
if ( str_input[ len_str_input-1 ] != ' ' ) {
strcat(str_input," ");
len_str_input++;
}
str_input[len_str_input]='\0';
g = r = counter_id_string=0;
//деление строки на слова
do{
if (str_input[counter_id_string] !=' '){
g=counter_id_string;
while(str_input[g]!=' '){
g++;
}
//момент создания подстроки
//E.g. Str="123"
//Str+1->"23"
//str_input+abs(counter_id_string-1)
strncpy(str[r], str_input+abs(counter_id_string-1),g-counter_id_string+1);
str[r][g-counter_id_string+1]='\0';
r++;
counter_id_string=g;
}
else counter_id_string++;
}while(counter_id_string != len_str_input-1 );
g=0;
counter_id_string=0;
counter_string=r;
//упорядочивание слов по алфавиту
for (i=0;i<counter_string;i++) {
k=0;
for(g=0;g<counter_string-i;g++) {
do{
char_of_two=str[g+1][k];
char_of_one=str[g][k];
k++;
}while(char_of_one==char_of_two);
if (char_of_one<char_of_two) {
strcpy(str_variable,str[g]);
strcpy(str[g],str[g+1]);
strcpy(str[g+1],str_variable);
}
k=0;
}
}
//вывод слов, упорядоченный по алфавиту
for (counter_string=r-1;counter_string>-1;counter_string--){
printf("str [%d] - ",counter_string);
puts(str[counter_string]);
}
fflush(stdin);
}
void main (void){
do {
addon();
fflush(stdin);
puts("\nExit - 1, Restart - any key");
} while ( getch() != '1');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment