All pastes #54747 Raw Edit

Unnamed

public text v1 · immutable
#54747 ·published 2006-05-10 13:14 UTC
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("list is empty\n");
    while (saras) {
        printf("%s\n", saras->eilute);
        saras = saras->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
    }
    
    spausdinti(sar1);   
    system("PAUSE");	
    return 0;
}