Thread: stopped working run time error.. help plz... ;(

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    82

    stopped working run time error.. help plz... ;(

    stopped working run time error.. help plz... ;(
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
        FILE *search;
        FILE *from;
        FILE *out;
        char cpy[4]="nono";
        char fro[100][50];
        char sear[50][50];
        from=fopen("from.txt","r");
        out=fopen("out.txt","w");
        int i=0;
    
        while(!feof(from))
        {
            fscanf(from,"%s",fro[i]);
            i++;
        }
        strcpy(fro[i],cpy);
        int j=i;
        i = 0;
    printf("ok");
        search=fopen("search.txt","r");
        while(!feof(search))
        {
            fscanf(from,"%s",sear[i]);
            i++;
        }
        strcpy(sear[i],cpy);
        int k=i;
        int l=0;
        i=0;
        while(!feof(from))
        {
            while(fro[i] != "nono")
    
            {
    
                for(i; i <k; i++)
                {
    
                    for(l; l<j; l++)
    
                    {
                        if(sear[l] == fro[i])
                        {
                            fprintf(out,"%s,",sear[l]);
                        }
                    }
    
                }
            }
    
        }
    
    
        getch();
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Please help me finding the error... :( <-- dupe thread, stop spamming

    Also, are you even paying attention to the compiler warnings? Use strcmp() on line 37, and fix everything else too.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    you need to give us more info. either put printfs in the code to find how far it gets, or step through it with a debugger to see where it barfs. also, in 'c' this doesn't work while(fro[i] != "nono"). you need to use strcmp there.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Why would you fix one occurance of the problem and not the other... then start a new thread?

    Really... look at line 37...

    So you know... C has absolutely no cognizence of text. It's all numerical. Instead; strings are stored as character arrays... arrays of numbers. But even arrays are second class citizens in the language. You cannot assign an array with = , you can't compare arrays using < > != etc. and you cannot return arrays from functions. The minimal text awareness C does have comes from library functions, prototyped in the string.h header.

    Yeah I know... WTF??? ... but that's the way it is.

    What you need to do is grab you C textbook and read up on strings in C ...

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    First are you sure your files are opening correctly? You should always insure your files open correctly because if they do not open correctly and you try to read from them you will get a runtime error.

    Also you can not compare C-strings with the operator!=, to compare C-strings you need to use strcmp().


    Jim

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    82
    now help me plz... :\

    search.txt:

    yeodkn

    eemrsh

    eylvlo

    rcthis

    erndsas

    leersb

    csesusc

    ilslona

    1kievn

    edbbie
    from.txt:
    html
    121212
    131313
    123123
    654321
    8675309
    666666
    696969
    888888
    1234567
    21122112
    12345678
    asdfjkl;
    hal9000
    bond007
    ncc1701d
    ncc1701e
    ncc1701
    thx1138
    a12345
    abcd1234
    1234qwer
    1a2b3c
    1q2w3e
    test123
    1p2o3i
    puppy123
    kitten12
    qwerty12
    john316
    apollo13
    ne1469
    amanda1
    mazda1
    angela1
    alpha1
    sarah1
    nirvana1
    bubba1
    scuba1
    rambo1
    charlie1
    david1
    digital1
    dragon1
    honda1
    shadow1
    eagle1
    freak1
    james1
    1sanjose
    apple1
    master1
    happy1
    martin1
    jason1
    larry1
    number1
    robert1
    soccer1
    direct1
    chester1
    welcome1
    french1
    hockey1
    chevy1
    scooter1
    chris1
    lucky1
    teddy1
    phoenix1
    hello1
    julie1
    kevin1
    pookie1
    viper1
    jenny1
    jesus1
    kelly1
    money1
    mouse1
    sting1
    justin1
    molly1
    sunny1
    front242
    jordan23
    2welcome
    h2opolo
    bird33
    4runner
    babylon5
    star69
    ib6ub9
    america7
    seven7
    number9
    porsche9
    barbara
    database
    banana
    bananas
    canada
    jamaica
    amanda
    valhalla
    samantha
    yamaha
    natasha
    alaska
    tamara
    zapata
    avatar
    basketba
    baseball
    basebal
    bastard
    nebraska
    banane
    abigail
    sabrina
    batman
    cocacola
    cascade
    cardinal
    claudia
    packard
    cannonda
    apache
    america
    canela
    camera
    caesar
    warcraft
    catalog
    chapman
    zachary
    alicia
    patricia
    carolina
    nicarao
    captain
    nautica
    pascal
    rascal
    camaro
    nascar
    deadhead
    adidas
    alexande
    airhead
    alexandr
    andrea
    gandalf
    grandma
    happyday
    indiana
    paladin
    miranda
    adrian
    dakota
    dallas
    mayday
    pandora
    sandra
    xanadu
    angela
    margaret
    stargate
    savage
    gateway
    athena
    ariane
    pearljam
    maryjane
    oatmeal
    pamela
    pantera
    vanessa
    graymail
    iguana
    jaguar
    galaxy
    gasman
    hannah
    hawaii
    mariah
    jonathan
    marshal
    martha
    nathan
    italia
    aikman
    saskia
    vanilla
    mailman
    animal
    animals
    impala
    attila
    marina
    mariposa
    nirvana
    arizona
    joanna
    january
    lakota
    avalon
    alyssa
    yomama
    montana
    mantra
    tazman
    tarzan
    starwars
    bobcat
    badboy
    barbie
    babies
    basketb
    rabbit
    bamboo
    rebecca
    abcdef
    abcdefg
    blackie
    excalibu
    campbell
    tacobell
    bigmac
    jsbach
    columbia
    buddha
    badger
    butthead
    bradley
    brenda
    bernard
    ladybug
    diablo
    blizzard
    brandi
    bandit
    brandon
    brandy
    beagle
    isabelle
    elizabet
    beanie
    beatles
    webmaste
    beaner
    beaver
    fireball
    beautifu
    gabriell
    gabriel
    poohbear
    bertha
    benjamin
    bailey
    beavis
    basket
    blaster
    albert
    blazer
    barney
    strawber
    braves
    buffalo
    football
    softball
    footbal
    foobar
    bigman
    gambit
    global
    malibu
    library
    brasil
    brazil
    rainbow
    obiwan
    kombat
    snowball
    marlboro
    snowbal
    playboy
    absolut
    wombat
    canced
    icecream
    chance
    celica
    cracker
    cancer
    access
    pacific
    chicago
    chocolat
    arctic
    clancy
    cactus
    dickhead
    maddock
    medical
    claude
    sundance
    dancer
    crawford
    richard
    wildcat
    picard
    colorado
    conrad
    corrado
    changeme
    chelsea
    peaches
    research
    teachers
    teacher
    creative
    cleaner
    france
    challeng
    michael
    charlie
    archie
    hacker
    chanel
    rachel
    charles
    patches
    jackie
    janice
    jessica
    maverick
    metallic
    caroline
    special
    claire
    iceman
    maurice
    maveric
    veronica
    carrie
    cassie
    active
    slacker
    packer
    packers
    marcel
    coltrane
    carole
    lacrosse
    scarlet
    scarlett
    castle
    carmen
    pacers
    racerx
    stacey
    catfish
    californ
    francois
    francis
    falcon
    graphic
    logical
    garlic
    camping
    racing
    cougars
    cougar
    chiquita
    christia
    nicholas
    champion
    cynthia
    charity
    charlott
    champs
    caitlin
    victoria
    tricia
    patrick
    calvin
    monica
    macintos
    action
    picasso
    jackson
    malcolm
    coolman
    classroo
    carlos
    crystal
    compaq
    tomcat
    marcus
    cannon
    corona
    cyrano
    topcat
    tractor
    laddie
    undead
    edward
    maddog
    diamond
    donald
    woodland
    greenday
    danielle
    dreamer
    reader
    garfield
    alfred
    reading
    gerald
    garden
    ........head
    daniel
    ireland
    raider
    raiders
    daytek
    leonard
    dreams
    anderson
    darren
    sanders
    andrew
    retard
    tuesday
    asdfghjk
    asdfgh
    dragonfl
    florida
    friday
    asdfjkl
    digital
    godzilla
    douglas
    dragon
    harold
    rhonda
    zaphod
    howard
    shadows
    shadow
    thursday
    indian
    island
    lindsay
    lizard
    madison
    pyramid
    darwin
    tardis
    wizard
    majordom
    jordan
    dollars
    orlando
    portland
    ronald
    rodman
    raymond
    monday
    sunday
    password
    passwd
    jeanette
    sweetpea
    jaeger
    general
    eagles
    heather
    kathleen
    hawkeye
    elephant
    sheena
    theresa
    theatre
    whatever
    whateve
    amelie
    melanie
    elaine
    valerie
    jeanne
    yankees
    walleye
    please
    seattle
    weasel
    awesome
    netware
    teresa
    grateful
    frankie
    fireman
    ferrari
    farmer
    safety
    maggie
    georgia
    aggies
    imagine
    galileo
    goalie
    enigma
    mirage
    wrangler
    angels
    german
    orange
    oranges
    ranger
    garnet
    voyager
    garrett
    target
    health
    katherin
    sheila
    stephani
    sapphire
    ..............
    harley
    stealth
    whales
    ashley
    hammer
    herman
    theman
    hamster
    matthew
    panther
    hearts
    harvey
    jasmine
    mikael
    mailer
    melissa
    valentin
    lorraine
    alpine
    aliens
    tequila
    reality
    laurie
    alexis
    sammie
    maxime
    marine
    vampire
    insane
    painter
    petunia
    praise
    pirate
    sierra
    asterix
    xavier
    jasper
    lakers
    walker
    kramer
    market
    tanker
    wanker
    parker
    startrek
    skater
    maxwell
    stella
    montreal
    temporal
    sampler
    marley
    samuel
    napoleon
    espanol
    snapple
    planet
    lauren
    stanley
    apples
    players
    player
    raquel
    slayer
    travel
    walter
    lestat
    superman
    masters
    master
    tanner
    suzanne
    newpass
    peanut
    warren
    tiffany
    wolfgang
    flamingo
    farming
    fugazi
    franklin
    family
    fountain
    wolfman
    smashing
    virginia
    sailing
    training
    stingray
    giants
    guitar
    magnum
    morgan
    mustang
    gymnast
    august
    mishka
    harrison
    spanish
    shanti
    joshua
    kathryn
    shalom
    hansolo
    phantom
    thomas
    shannon
    hanson
    anthony
    sharon
    hatton
    author
    arthur
    nikita
    williams
    william
    raistlin
    olivia
    julian
    jasmin
    allison
    marilyn
    alison
    polaris
    sailor
    quality
    sylvia
    ironman
    mountain
    tinman
    marino
    martin
    marvin
    matrix
    nissan
    passion
    station
    tristan
    austin
    utopia
    warriors
    warrior
    artist
    travis
    krystal
    spanky
    sparky
    apollo
    salmon
    psalms
    larson
    royals
    taylor
    norman
    snowman
    sampson
    samson
    mozart
    watson
    saturn
    tattoo
    toyota
    sparrow
    parrot
    passwor
    qwaszx
    stuart
    taurus
    bubbles
    debbie
    bluebird
    bigbird
    pebbles
    robbie
    hobbit
    jimbob
    booboo
    december
    quebec
    robotech
    republic
    october
    public
    zxcvbnm
    broncos
    cowboys
    scooby
    cowboy
    firebird
    bigred
    bridges
    dogbert
    thunderb
    birdie
    blondie
    dilbert
    doobie
    blonde
    rosebud
    bigdog
    bulldog
    sunbird
    remember
    septembe
    homebrew
    herbert
    biteme
    bernie
    reebok
    rebels
    byteme
    brewster
    webster
    boogie
    junebug
    goblue
    goober
    shelby
    theboss
    kimberly
    zombie
    timber
    bonnie
    benoit
    business
    nesbitt
    bootsie
    bluesky
    brooke
    volleyb
    bullet
    blowme
    trouble
    butler
    boomer
    benson
    booster
    trebor
    buster
    bigfoot
    blowfish
    bright
    bowling
    biology
    gibson
    bull........
    robinhoo
    bookit
    wilbur
    bonjour
    symbol
    boston
    browns
    buttons
    button
    brutus
    cccccc
    electric
    science
    chicken
    cricket
    celtics
    cyclone
    connect
    concept
    soccer
    success
    church
    chucky
    scotch
    cloclo
    cuddles
    depeche
    mercedes
    frederic
    deutsch
    duckie
    wicked
    cinder
    director
    orchid
    dominic
    doctor
    cheese
    coffee
    fletcher
    gretchen
    college
    michelle
    michele
    speech
    chester
    celine
    eclipse
    pierce
    service
    colleen
    telecom
    welcome
    spencer
    center
    except
    secret
    chiefs
    fletch
    ........me
    ........er
    michell
    mitchell
    michel
    chipper
    hockey
    cheryl
    techno
    porsche
    hector
    cherry
    justice
    pickle
    mickey
    snicker
    snickers
    cookie
    cookies
    nicole
    police
    clipper
    mexico
    connie
    vincent
    prince
    princess
    picture
    pisces
    security
    cruise
    rocket
    puckett
    tucker
    clover
    computer
    compute
    mercury
    newcourt
    courtney
    cooper
    scooter
    coyote
    copper
    ........off
    scruffy
    fiction
    ........you
    gocougs
    christin
    christop
    chrissy
    christ
    christy
    school
    psycho
    politics
    knicks
    lincoln
    unicorn
    scorpion
    corwin
    sonics
    scorpio
    victor
    victory
    curtis
    trucks
    control
    compton
    moocow
    cosmos
    popcorn
    xcountry
    country
    scotty
    deedee
    dundee
    freddy
    dodger
    dodgers
    defense
    freedom
    fender
    legend
    deliver
    denise
    kennedy
    ledzep
    denver
    speedo
    speedy
    dexter
    friend
    friends
    doggie
    digger
    goldie
    redwing
    design
    doogie
    dougie
    golden
    hendrix
    thunder
    inside
    kinder
    redskin
    dookie
    lindsey
    dennis
    trident
    sendit
    sidney
    detroit
    spider
    strider
    donkey
    reynolds
    elwood
    redrum
    wonder
    notused
    student
    sydney
    windsurf
    oxford
    midnight
    dwight
    hotdog
    indigo
    kingdom
    snoopdog
    gordon
    phurivdli
    judith
    dolphin
    dolphins
    hotrod
    dorothy
    midori
    skidoo
    domino
    nimrod
    wisdom
    windows
    dustin
    stupid
    drizzt
    london
    studly
    voodoo
    peewee
    reefer
    eugene
    sweetie
    kleenex
    skeeter
    penelope
    steelers
    steele
    eeyore
    weezer
    jeffrey
    jennifer
    jenifer
    ferret
    reggie
    george
    wheeling
    genesis
    sergei
    energy
    hershey
    kenneth
    shelley
    helpme
    wheels
    promethe
    hermes
    stephen
    einstein
    jessie
    nellie
    leslie
    letmein
    zeppelin
    etoile
    nemesis
    internet
    pierre
    jewels
    jeremy
    jensen
    jester
    kelsey
    loveme
    people
    explorer
    wrestle
    letter
    wesley
    velvet
    western
    newuser
    steven
    popeye
    europe
    pepper
    express
    tester
    stever
    testtest
    sweets
    sweety
    tweety
    griffey
    golfer
    fisher
    spitfire
    flipper
    xfiles
    fozzie
    sunflowe
    flowers
    flower
    flyers
    forest
    surfer
    future
    ginger
    tigger
    google
    nugget
    gregory
    theking
    gopher
    gemini
    gilles
    piglet
    penguin
    guinness
    singer
    testing
    genius
    tigers
    gretzky
    gunner
    nguyen
    grover
    shirley
    memphis
    sunshine
    phoenix
    whitney
    zenith
    hootie
    sophie
    joseph
    huskers
    shelly
    mother
    thumper
    hornets
    hornet
    hunter
    shooter
    topher
    horses
    zephyr
    sherry
    millie
    willie
    olivier
    minnie
    winnie
    trixie
    jupiter
    killme
    killer
    mookie
    kermit
    kristen
    tinker
    kittens
    kitten
    pookie
    skipper
    miller
    soleil
    elliot
    little
    merlin
    simple
    smiles
    smiley
    online
    wolverin
    liverpoo
    iloveyou
    oliver
    louise
    violet
    silver
    sylvie
    mortimer
    swimmer
    emmitt
    monique
    pentium
    mittens
    niners
    intern
    winner
    tennis
    senior
    sniper
    sunrise
    winter
    tootsie
    puppies
    ripper
    sprite
    monkey
    smokey
    network
    newyork
    volley
    yellow
    russell
    lennon
    nelson
    looney
    loveyou
    protel
    wolves
    purple
    russel
    turtle
    memory
    summer
    monster
    vermont
    trumpet
    system
    newton
    yvonne
    runner
    preston
    entropy
    reznor
    sunset
    rooster
    property
    porter
    export
    trevor
    qwerty
    fluffy
    muffin
    snuffy
    golfing
    froggy
    kingfish
    fishing
    flight
    gofish
    goforit
    informix
    pinkfloy
    foxtrot
    frosty
    zhongguo
    knights
    knight
    nothing
    hunting
    wright
    shotgun
    lionking
    skiing
    vikings
    viking
    swimming
    running
    roping
    spring
    grumpy
    topgun
    groovy
    phillip
    philip
    whisky
    timothy
    smiths
    sunshin
    horizon
    history
    johnson
    johnny
    murphy
    houston
    python
    shorty
    kristin
    kristi
    million
    mission
    tintin
    vision
    spirit
    junior
    justin
    pumpkin
    punkin
    skinny
    stinky
    skippy
    kristy
    suzuki
    willow
    wilson
    moroni
    mirror
    morris
    stimpy
    winston
    poiuyt
    squirt
    spunky
    spooky
    monopoly
    molson
    moomoo
    stormy
    toronto
    snoopy
    support
    sports
    printing only one ok of line 15.. problem is above....
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
        FILE *search;
        FILE *from;
        FILE *out;
        char cpy[4]="nono";
        char fro[100][50];
        char sear[50][50];
        from=fopen("from.txt","r");
        out=fopen("out.txt","w");
        int i=0;
        printf("ok");
        while(!feof(from))
        {
            fscanf(from,"%s",fro[i]);
            i++;
        }
        strcpy(fro[i],cpy);
        int j=i;
        i = 0;
    printf("ok");
        search=fopen("search.txt","r");
        while(!feof(search))
        {
            fscanf(from,"%s",sear[i]);
            i++;
        }
        strcpy(sear[i],cpy);
        int k=i;
        int l=0;
        i=0;
        while(!feof(from))
        {
            while(fro[i] != "nono")
    
            {
    
                for(i; i <k; i++)
                {
    
                    for(l; l<j; l++)
    
                    {
                        if(sear[l] == fro[i])
                        {
                            fprintf(out,"%s,",sear[l]);
                        }
                    }
    
                }
            }
    
        }
    
    
        getch();
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    check your return codes from the two fopens and the fscanf

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    • As Jim said, you need to check the return value from each fopen call, and quit with an error if you can't open something.
    • Read this: FAQ > Why it's bad to use feof() to control a loop - Cprogramming.com
    • Your from array only has room for 100 words, but your file has over 1200 words in it. Massive buffer overflow there.
    • Where does this magical "nono" string come from. I don't see it in either from.txt or search.txt. Your while loop will never stop. EDIT: Nevermind, I see it now. Didn't show up when I searched for some reason.
    • Pick better names. j should be something like num_source_words and k something like num_search_words. Then you would see your indexes for sear and fro in your search loops are backwards.
    • Use a normal for loop. Put the initializer in the first part, otherwise, your for(l; ...) loop wont reset l each time and your searches will fail. Do for(i = 0; i < k; i++) and the same with for (l = 0; ...).


    Honestly, you need to sit down and plan and think before you touch the keyboard. Work out a solution with paper and pencil first, and run through some tests by hand. Then, code in small increments (5-10 lines) and test as you go.
    Last edited by anduril462; 01-03-2012 at 04:38 PM.

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by fredsilvester93 View Post
    now help me plz... :\
    Not much point, since it's apparent you aren't following any of the suggestions we've given you so far.

    Your problem is still on line 37, where you're attempting to compare strings with != ... C can't do that. Look in your library documentation for a function that can.

  10. #10
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Quote Originally Posted by CommonTater View Post
    Not much point, since it's apparent you aren't following any of the suggestions we've given you so far.

    Your problem is still on line 37, where you're attempting to compare strings with != ... C can't do that. Look in your library documentation for a function that can.
    And if you're too lazy to look in your documentation, scroll up and see how three people told you the answer, and all you did was blow it off by implying that we weren't helping.

  11. #11
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > char cpy[4]="nono";
    Whilst this is legal C, it is NOT a legal C-string. It does NOT have a trailing \0.
    If you want a char array, then it's far better to just leave the [ ] empty and let the compiler do the counting for you.

    > char sear[50][50];
    I counted 1274 words in your word list - how many did you count?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ****.exe has stopped working
    By kawaikx15 in forum C Programming
    Replies: 10
    Last Post: 11-19-2011, 07:38 AM
  2. .exe has stopped working
    By bluesky16 in forum C++ Programming
    Replies: 8
    Last Post: 02-21-2011, 12:58 PM
  3. vshost.exe has stopped working
    By Marty21 in forum C# Programming
    Replies: 1
    Last Post: 06-08-2009, 10:41 AM
  4. Replies: 4
    Last Post: 03-26-2008, 08:48 AM
  5. Mouse scroll stopped working
    By Waldo2k2 in forum Tech Board
    Replies: 2
    Last Post: 10-12-2004, 11:25 AM