Runtime error for a simple scenario

This is a discussion on Runtime error for a simple scenario within the C++ Programming forums, part of the General Programming Boards category; hi ... my i/p canbe of format. $ $ $ . . $ $ . $ . . $ here ...

  1. #1
    dpp
    dpp is offline
    Registered User
    Join Date
    Jan 2009
    Posts
    197

    Runtime error for a simple scenario

    hi ...
    my i/p canbe of format.
    $ $ $ . . $
    $ . $ . . $
    here the number of rows and cols is 2 and 5.
    i have to consider whenevr the dots come into play.
    as i encou nter each dot i increment a counter meaning that is 1st dot,2nd dot and so on...
    in the first row i have two dots... so i name them as 1 and 2...
    whenever 2 dots are adjacent or one below the other i need to associate those dots...
    here in the i/p above i have to associate
    1 2
    1 4
    and 2 5

    this seems to be simple...but am getting runtime error for the following processing... can anyone help me plzz....
    Code:
    #include<iostream>
    #include<string.h>
    #define max 100
    using namespace std;
    int main()
    {
    long long int t,i,j,count=0,a[max][max],m,n;
    char c[max][max];
    
    cin>>m>>n;
    
    for(i=0;i<n;i++)
    {
    for(j=0;j<m;j++)
      {
    scanf("%c",&c[i][j]);
    
    if((c[i][j]=='.')&&(count==0))
           {
              count++;
              a[i][j]=count;
              goto s10;
            }
    if((c[i][j]=='.')&&(count!=0))
              {        
               count++;
               a[i][j]=count;
               if(i!=0)
                    if(c[i-1][j]=='.') cout<<"\n"<<a[i-1][j]<<"and"<<a[i][j];
                if(j!=0)
                      if(c[i][j-1]=='.') cout<<"\n"<<a[i][j-1]<<"and"<<a[i][j];
               }
    s10:
    ;
    }
    }
    return 0;
    }
    Last edited by dpp; 02-22-2009 at 02:03 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Your code is an unindented mess with goto statements.
    Nobody wants to go anywhere near it.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    dpp
    dpp is offline
    Registered User
    Join Date
    Jan 2009
    Posts
    197
    well i ve indented now....
    the idea is simple....that anybody can understand

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    No, you have not properly indented your code, and you should redo the code such that it does not use goto.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    You still have a row of } in the left column.

    Try this
    Code:
    #include<iostream>
    #include<string.h>
    #define max 100
    using namespace std;
    int main()
    {
        long long int t,i,j,count=0,a[max][max],m,n;
        char c[max][max];
    
        cin>>m>>n;
    
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%c",&c[i][j]);
    
                if((c[i][j]=='.')&&(count==0))
                {
                    count++;
                    a[i][j]=count;
                    goto s10;
                }
                if((c[i][j]=='.')&&(count!=0))
                {        
                    count++;
                    a[i][j]=count;
                    if(i!=0)
                    if(c[i-1][j]=='.') cout<<"\n"<<a[i-1][j]<<"and"<<a[i][j];
                    if(j!=0)
                    if(c[i][j-1]=='.') cout<<"\n"<<a[i][j-1]<<"and"<<a[i][j];
                }
    s10:
                ;
            }
        }
        return 0;
    }
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    Now that's done, consider replacing the goto with an else
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  3. Help me with these simple programs
    By Help me in forum C Programming
    Replies: 4
    Last Post: 11-08-2001, 09:38 AM
  4. Need help with simple data types
    By partnole in forum C++ Programming
    Replies: 1
    Last Post: 10-03-2001, 08:36 AM
  5. Linker errors with simple static library
    By Dang in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2001, 09:38 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21