Keresés

Hirdetés

Új hozzászólás Aktív témák

  • blaces

    tag

    válasz Jester01 #1006 üzenetére

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #define IGAZ 1
    #define HAMIS !IGAZ


    typedef struct listaelem{
    char szo[50];
    struct listaelem *kov;
    }LISTAELEM;

    int abszolut(int a,int b)
    { int c;
    c=(a-b)>=0 ? (a-b):(a-b)*(-1);
    return c;
    }

    int keres(LISTAELEM *fej,char sz[])
    {
    LISTAELEM *seged;
    for(seged=fej;seged;seged=seged->kov)
    {
    if(strcmp(sz,seged->szo)!=0)
    return IGAZ;
    }
    return HAMIS;

    }

    LISTAELEM* beszur(LISTAELEM *fej,char szo[])
    {
    LISTAELEM *ujelem=(LISTAELEM*)malloc(sizeof(LISTAELEM));
    strcpy(ujelem->szo,szo);
    ujelem->kov=NULL;
    if(!fej)
    return ujelem;
    else
    {
    LISTAELEM *seg=fej;
    while(seg->kov)
    seg=seg->kov;
    seg->kov=ujelem;
    }
    return fej;
    }

    LISTAELEM* feldolgoz(FILE *f,LISTAELEM *fej)
    {
    char betu,sz[50];
    int j,i=0;
    int h=strlen(sz);
    while( (betu=fgetc(f)) !=EOF)
    {
    if(betu==' ' || betu==',' || betu=='!' || betu=='?' || betu=='.' || betu=='\n')
    {
    if(h>2)
    {
    fej=beszur(fej,sz);
    for(j=0;j<50;j++)
    sz[j]='\0';
    i=0;
    }
    }
    else
    {
    sz[i]=tolower(betu);
    i++;
    }
    }
    return fej;
    }

    int gyak(LISTAELEM *fej,char sz[])
    {
    LISTAELEM *seg;
    int gyakorisag=0;
    for(seg=fej;seg;seg=seg->kov)
    {
    if(strcmp(seg->szo,sz)==0)
    gyakorisag++;
    }
    return gyakorisag;
    }

    int main(int argc,char **argv)
    {
    FILE *f1,*f2;
    LISTAELEM *fej1=NULL,*fej2=NULL,*fej3=NULL,*seged=NULL;
    int gyak1,gyak2,szavak=0,n;
    float hasonlosag=0,eredm;

    f1=fopen(argv[1],"r");
    f2=fopen(argv[2],"r");
    fej1=feldolgoz(f1,fej1);
    fej2=feldolgoz(f2,fej2);

    for(seged=fej1;seged;seged=seged->kov)
    {
    if((n=keres(fej3,seged->szo))==0)
    {
    gyak1=gyak(fej1,seged->szo);
    gyak2=gyak(fej2,seged->szo);
    hasonlosag+=(abszolut(gyak1,gyak2))/(gyak1+gyak2);
    szavak++;
    }
    }

    for(seged=fej2;seged;seged=seged->kov)
    {
    if((n=keres(fej3,seged->szo))==0)
    {
    gyak1=gyak(fej1,seged->szo);
    gyak2=gyak(fej2,seged->szo);
    hasonlosag+=(abszolut(gyak1,gyak2))/(gyak1+gyak2);
    szavak++;
    }
    }

    eredm=hasonlosag/szavak;
    printf("%.5f\n",eredm);

    return 0;
    }

    valgrind -v eredmények:
    ==3173== Memcheck, a memory error detector.
    ==3173== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
    ==3173== Using LibVEX rev 1658, a library for dynamic binary translation.
    ==3173== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
    ==3173== Using valgrind-3.2.1-Debian, a dynamic binary instrumentation framework.
    ==3173== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
    ==3173==
    --3173-- Command line
    --3173-- ./elso
    --3173-- Startup, with flags:
    --3173-- -v
    --3173-- Contents of /proc/version:
    --3173-- Linux version 2.6.18-6-xen-amd64 (Debian 2.6.18.dfsg.1-23etch1) (dannf@debian.org) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Fri Dec 12 07:02:03 UTC 2008
    --3173-- Arch and hwcaps: AMD64, amd64-sse2
    --3173-- Valgrind library directory: /usr/lib/valgrind
    --3173-- Reading syms from /home/izgatopasi/Prog1/3/1/elso (0x400000)
    --3173-- Reading syms from /lib/ld-2.3.6.so (0x4000000)
    --3173-- Reading debug info from /lib/ld-2.3.6.so...
    --3173-- ... CRC mismatch (computed 1CBD6C2C wanted 509BB065)
    --3173-- object doesn't have a symbol table
    --3173-- Reading syms from /usr/lib/valgrind/amd64-linux/memcheck (0x38000000)
    --3173-- object doesn't have a dynamic symbol table
    --3173-- Reading suppressions file: /usr/lib/valgrind/default.supp
    --3173-- Reading syms from /usr/lib/valgrind/amd64-linux/vgpreload_core.so (0x4918000)
    --3173-- Reading syms from /usr/lib/valgrind/amd64-linux/vgpreload_memcheck.so (0x4A19000)
    --3173-- Reading syms from /lib/libc-2.3.6.so (0x4B1F000)
    --3173-- Reading debug info from /lib/libc-2.3.6.so...
    --3173-- ... CRC mismatch (computed AD7708C1 wanted 5D81B887)
    --3173-- object doesn't have a symbol table
    --3173-- REDIR: 0x4B91980 (rindex) redirected to 0x4A1C450 (rindex)
    --3173-- REDIR: 0x4B8D0F0 (malloc) redirected to 0x4A1B7D6 (malloc)
    ==3173== Syscall param open(filename) points to unaddressable byte(s)
    ==3173== at 0x4BDB152: open (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B85F52: _IO_file_open (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B8609B: _IO_file_fopen (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B7C053: (within /lib/libc-2.3.6.so)
    ==3173== by 0x4008B9: main (1_feladat.c:94)
    ==3173== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    --3173-- REDIR: 0x4B8B180 (free) redirected to 0x4A1B3E6 (free)
    ==3173==
    ==3173== Conditional jump or move depends on uninitialised value(s)
    ==3173== at 0x400771: feldolgoz (1_feladat.c:53)
    ==3173== by 0x4008E3: main (1_feladat.c:96)
    ==3173==
    ==3173== Invalid read of size 2
    ==3173== at 0x4B82DE1: getc (in /lib/libc-2.3.6.so)
    ==3173== by 0x400801: feldolgoz (1_feladat.c:54)
    ==3173== by 0x4008E3: main (1_feladat.c:96)
    ==3173== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==3173==
    ==3173== Process terminating with default action of signal 11 (SIGSEGV)
    ==3173== Access not within mapped region at address 0x0
    ==3173== at 0x4B82DE1: getc (in /lib/libc-2.3.6.so)
    ==3173== by 0x400801: feldolgoz (1_feladat.c:54)
    ==3173== by 0x4008E3: main (1_feladat.c:96)
    --3173-- REDIR: 0x4B92830 (memset) redirected to 0x4A1C960 (memset)
    ==3173==
    ==3173== ERROR SUMMARY: 6 errors from 3 contexts (suppressed: 8 from 1)
    ==3173==
    ==3173== 1 errors in context 1 of 3:
    ==3173== Invalid read of size 2
    ==3173== at 0x4B82DE1: getc (in /lib/libc-2.3.6.so)
    ==3173== by 0x400801: feldolgoz (1_feladat.c:54)
    ==3173== by 0x4008E3: main (1_feladat.c:96)
    ==3173== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==3173==
    ==3173== 1 errors in context 2 of 3:
    ==3173== Syscall param open(filename) points to unaddressable byte(s)
    ==3173== at 0x4BDB152: open (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B85F52: _IO_file_open (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B8609B: _IO_file_fopen (in /lib/libc-2.3.6.so)
    ==3173== by 0x4B7C053: (within /lib/libc-2.3.6.so)
    ==3173== by 0x4008B9: main (1_feladat.c:94)
    ==3173== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==3173==
    ==3173== 4 errors in context 3 of 3:
    ==3173== Conditional jump or move depends on uninitialised value(s)
    ==3173== at 0x400771: feldolgoz (1_feladat.c:53)
    ==3173== by 0x4008E3: main (1_feladat.c:96)
    --3173--
    --3173-- supp: 8 Debian libc6 (2.3.x) stripped dynamic linker
    ==3173==
    ==3173== IN SUMMARY: 6 errors from 3 contexts (suppressed: 8 from 1)
    ==3173==
    ==3173== malloc/free: in use at exit: 0 bytes in 0 blocks.
    ==3173== malloc/free: 2 allocs, 2 frees, 1,136 bytes allocated.
    ==3173==
    ==3173== All heap blocks were freed -- no leaks are possible.
    --3173-- memcheck: sanity checks: 0 cheap, 1 expensive
    --3173-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use
    --3173-- memcheck: auxmaps: 0 searches, 0 comparisons
    --3173-- memcheck: SMs: n_issued = 12 (192k, 0M)
    --3173-- memcheck: SMs: n_deissued = 0 (0k, 0M)
    --3173-- memcheck: SMs: max_noaccess = 524287 (8388592k, 8191M)
    --3173-- memcheck: SMs: max_undefined = 0 (0k, 0M)
    --3173-- memcheck: SMs: max_defined = 66 (1056k, 1M)
    --3173-- memcheck: SMs: max_non_DSM = 12 (192k, 0M)
    --3173-- memcheck: max sec V bit nodes: 0 (0k, 0M)
    --3173-- memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0)
    --3173-- memcheck: max shadow mem size: 4336k, 4M
    --3173-- translate: fast SP updates identified: 921 ( 86.7%)
    --3173-- translate: generic_known SP updates identified: 90 ( 8.4%)
    --3173-- translate: generic_unknown SP updates identified: 51 ( 4.8%)
    --3173-- tt/tc: 2,648 tt lookups requiring 2,655 probes
    --3173-- tt/tc: 2,648 fast-cache updates, 2 flushes
    --3173-- transtab: new 1,324 (31,539 -> 556,589; ratio 176:10) [0 scs]
    --3173-- transtab: dumped 0 (0 -> ??)
    --3173-- transtab: discarded 0 (0 -> ??)
    --3173-- scheduler: 23,425 jumps (bb entries).
    --3173-- scheduler: 0/1,389 major/minor sched events.
    --3173-- sanity: 1 cheap, 1 expensive checks.
    --3173-- exectx: 30,011 lists, 15 contexts (avg 0 per list)
    --3173-- exectx: 18 searches, 4 full compares (222 per 1000)
    --3173-- exectx: 0 cmp2, 39 cmp4, 0 cmpAll

    valgrind eredmény (simán csak valgrind [nev]):
    ==3298== Memcheck, a memory error detector.
    ==3298== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
    ==3298== Using LibVEX rev 1658, a library for dynamic binary translation.
    ==3298== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
    ==3298== Using valgrind-3.2.1-Debian, a dynamic binary instrumentation framework.
    ==3298== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
    ==3298== For more details, rerun with: -v
    ==3298==
    ==3298== Syscall param open(filename) points to unaddressable byte(s)
    ==3298== at 0x4BDB152: open (in /lib/libc-2.3.6.so)
    ==3298== by 0x4B85F52: _IO_file_open (in /lib/libc-2.3.6.so)
    ==3298== by 0x4B8609B: _IO_file_fopen (in /lib/libc-2.3.6.so)
    ==3298== by 0x4B7C053: (within /lib/libc-2.3.6.so)
    ==3298== by 0x4008B9: main (1_feladat.c:94)
    ==3298== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==3298==
    ==3298== Conditional jump or move depends on uninitialised value(s)
    ==3298== at 0x400771: feldolgoz (1_feladat.c:53)
    ==3298== by 0x4008E3: main (1_feladat.c:96)
    ==3298==
    ==3298== Invalid read of size 2
    ==3298== at 0x4B82DE1: getc (in /lib/libc-2.3.6.so)
    ==3298== by 0x400801: feldolgoz (1_feladat.c:54)
    ==3298== by 0x4008E3: main (1_feladat.c:96)
    ==3298== Address 0x0 is not stack'd, malloc'd or (recently) free'd
    ==3298==
    ==3298== Process terminating with default action of signal 11 (SIGSEGV)
    ==3298== Access not within mapped region at address 0x0
    ==3298== at 0x4B82DE1: getc (in /lib/libc-2.3.6.so)
    ==3298== by 0x400801: feldolgoz (1_feladat.c:54)
    ==3298== by 0x4008E3: main (1_feladat.c:96)
    ==3298==
    ==3298== ERROR SUMMARY: 6 errors from 3 contexts (suppressed: 8 from 1)
    ==3298== malloc/free: in use at exit: 0 bytes in 0 blocks.
    ==3298== malloc/free: 2 allocs, 2 frees, 1,136 bytes allocated.
    ==3298== For counts of detected errors, rerun with: -v
    ==3298== All heap blocks were freed -- no leaks are possible.
    Szegmens hiba

    [ Szerkesztve ]

Új hozzászólás Aktív témák