Thread: Small program crash with C++ Bloodshev

  1. #1
    Registered User
    Join Date
    Nov 2008

    Small program crash with C++ Bloodshev

    this is my code
    #include <stdio.h>//standard input and output
    #include <stdlib.h>//standard library
    #include <math.h>
    #include <string.h>
    #include <ctype.h>
     char *database[100][100]={{"Z","L","A","N","K"},{"H","B","A"},{"B","H"},{"B","A"},{"H","G"},{"H","G","F"},{"H","G","F","K"},{"H","G","F","K","L"},
     char initial,pointer[100],final[0][0],results,pointer2[100][100];
     char database2[100][100]={{"Blank"},{"HBA"},{"BH"},{"BA"},{"HG"},{"HGF"},{"HGFK"},{"HGFKL"},{"HGL"},{"HGLF"},{"HGM"},{"HGMQ"},
     int i,j,test;
     int main()
    puts("Enter the starting point");
    puts("Enter the ending point");
    if (strcmp(&initial,&pointer[i])==0)
    for (j=0;j<100;j++)
    if ((strcmp(&final[0][0],&pointer2[i][j])==0))

    It crashes after it had found a letter in the database that matches the first letter of the initial input. The purpose is just to find a string in the database that matches the given starting letter and ending letter.

    I'm not sure why it crashes... sorry if this is asking a lot. oh and i moved the database a little to not stretch the post

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    Oh... my... goodness! Horrible code.
    1) Indent.
    2) Never use gets:
    3) Why do you think it crashes when you pass the value of final[0][0] which is 0? You are passing a value, not an address. Enable warnings!
    4) How do you expect it to be able to read something when there's no space to store it in?

    And this is pure and utter C, not C++. Thank you very much.
    These are just a small portion of what's wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Before you populate it with 100, try it with a small number, like 5.

    > final[0][0]
    How many chars does this hold?
    as many as you like
    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.

  4. #4
    Registered User
    Join Date
    Nov 2008
    oh. Thank you for the help. its working better.
    my bad on the wrong section thing. I just looked at the top right and it said Dev-C++ :S

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. my program crash?
    By vrkiller in forum C++ Programming
    Replies: 10
    Last Post: 03-04-2009, 03:03 PM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Problem using structures (they crash my program)
    By shadow1515 in forum C Programming
    Replies: 7
    Last Post: 06-17-2008, 08:36 AM
  4. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 10:52 AM
  5. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM