rendered paste body#include <stdlib.h> /* malloc */
#include <stdio.h>
#include <string.h>
#define ilgis 100
typedef struct sarasas {
char eilute[ilgis];
struct sarasas *next;
struct sarasas *prev;
} sar;
void naujas(sar **saras, char *zod) {
sar *tmp;
tmp = (sar*) malloc (sizeof(sar));
strcpy(tmp->eilute,zod);
tmp->next = *saras;
tmp->prev = NULL;
*saras = tmp;
}
void spausdinti(sar *saras) {
if (saras == NULL) printf("Sarasas yra tuscias\n");
while (saras) {
printf("%s\n", saras->eilute);
saras = saras->next;
}
}
/* bandziau bet sh primaliau tik*/
void rikiavimas (sar **saras){
sar *i, *j,*x;
i = *saras;
if (i!=NULL){
while (i->next!=NULL) {
j = i->next;
while ((j!=NULL) && (j->eilute>=i->eilute)) j=j->next;
if (j != NULL){
x = i;
i=j;
j=x;
}
i=i->next;
}}
}
int main(){
sar *sar1;
sar1=NULL;
printf("Iveskite norima zodzio galune: " );
char str[3];
scanf("%s",str);
FILE *F = fopen("duom.txt", "r"); // atidaromas failas skaitymui
if (F){
char S[ilgis];
while (!feof(F)){
fscanf(F, "%s",S);
if ( strstr(S, str) >= S+strlen(S)-strlen(str)) naujas(&sar1,S);
}
fclose(F); //uzdaryti faila
}
rikiavimas(&sar1);
spausdinti(sar1);
system("PAUSE");
return 0;
}