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) {
FILE *F = fopen("rex.txt", "w");
if (saras == NULL) fprintf(F,"Sarasas yra tuscias\n");
while (saras) {
fprintf(F,"%s\n", saras->eilute);
saras = saras->next;
}
}
/* bandziau bet sh primaliau tik*/
void rikiavimas (sar **saras){
sar *i, *j;
char x[ilgis];
i = *saras;
if (i!=NULL){
while (i->next!=NULL) {
j = i->next;
if (strcmp(i->eilute,j->eilute)>1) {
strcpy(x,i->eilute);
strcpy(i->eilute,j->eilute);
strcpy(j->eilute, 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;
}