Like Tree3Likes
  • 2 Post By Matticus
  • 1 Post By anduril462

decleration terminated incorrectly in turbo c

This is a discussion on decleration terminated incorrectly in turbo c within the C Programming forums, part of the General Programming Boards category; please help sorting out the error insert Code: #include<stdio.h> #include<conio.h> { void main() int a[10][10],b[10][10],q,w,e,r,i,j,k,l; printf("Enter the size of first ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    23

    decleration terminated incorrectly in turbo c

    please help sorting out the error
    insert
    Code:
    #include<stdio.h>
    #include<conio.h>
    {
    void main()
    int a[10][10],b[10][10],q,w,e,r,i,j,k,l;
    printf("Enter the size of first matrix : ");
    scanf("%d",&q,&w);
    printf("Enter the size of the second matrix : ");
    scanf("%d",&e,&r);
    printf(" Type elements");
    for(i=1;i<=w;i++)
    {
    for(j=1;j<=q;j++)
    {
    scanf("%d",&a[i][j]);
    }
    }
    for(i=1;i<=w;i++)
    {
    for(j=1;j<=q;j++)
    {
    printf("%d",a[i][j]);
    }
    printf("\n");
    }
    printf("Type elements");
    for(k=1;k<=w;+k+)
    {
    for(l=1;l<=q;l++)
    {
    scanf("%d",&b[k][l]);
    }
    }
    for(k=1;k<=w;+k+)
    {
    for(l=1;l<=q;l++)
    {
    printf("%d",b[k][l]);
    }
    printf("\n");
    }
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Can you post the exact error? It should give you a line and column number that tells you exactly where there's a mistake. Also, if you can add the proper indentation it makes it much easier to scan through and spot the kind of problem you're talking about.

    edit: Though I suspect it's something to do with your single line that includes multiple arrays. I don't recall all the rules for declarations like that, but I'd suggest you play around with that line (i.e. separating it to multiple lines) to see if you can track down which combination is causing the error.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    23
    Quote Originally Posted by sean View Post
    Can you post the exact error? It should give you a line and column number that tells you exactly where there's a mistake. Also, if you can add the proper indentation it makes it much easier to scan through and spot the kind of problem you're talking about.

    edit: Though I suspect it's something to do with your single line that includes multiple arrays. I don't recall all the rules for declarations like that, but I'd suggest you play around with that line (i.e. separating it to multiple lines) to see if you can track down which combination is causing the error.
    it gives me error around line 3

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,273
    Well, for starters, the brace that is supposed to go after your "main()" declaration is, for some reason, before your "main()" declaration.

    And you should declare "main()" as returning an int, and return an integer at the end:

    Code:
    int main(void)
    {
        // ...
        return 0;
    }
    If you're not using any functions from "conio.h", get rid of it - it's non-standard anyway.

    And be careful of copy+pasting mistakes:

    Code:
    for(k=1;k<=w;+k+)
    {
        for(l=1;l<=q;l++)
        {
            scanf("%d",&b[k][l]);
        }
    }
    
    for(k=1;k<=w;+k+)
    {
        for(l=1;l<=q;l++)
        {
            printf("%d",b[k][l]);
        }
    printf("\n");
    }

  5. #5
    Dweeb dojha00's Avatar
    Join Date
    Feb 2012
    Location
    Global
    Posts
    23
    Line 27 and 34, what are u trying to do ('+k+') ??
    and again which input is for row and which one is for column quite confusing use proper variables....

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    2,273
    Oh, and if you typed all of that before you even compiled once, then you're not using good programming techniques. You should always type some code, compile, fix errors/warnings, verify it works as expected - add some more code, etc. Take it step by step. Don't just dump a page of code and wonder why it isn't working.

    A development process
    stahta01 and Salem like this.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,459
    Consider upgrading your compiler. Turbo C is ancient, and no longer supported. Don't use Dev-C++ either, it's also old, outdated and unsupported. There are many better, free, and current alternatives, such as Code::Blocks with MinGW, Pelles C, and MS Visual C++ even has a free version that compiles C. MSVC++ is also a bit outdated (not supporting the standard developed back in 1999), but is still supported/developed by MS.

    All the suggestions of the previous posters need to be addressed, as well as the following issues:

    Your indentation is non-existent. Indent your code properly, it helps make your code readable. Readable code means fewer mistakes.
    Code:
    int a[10][10],b[10][10],q,w,e,r,i,j,k,l;
    Those are horrible variable names, nobody has any idea what each one of those variables does, including you. You are using the wrong size variables for reading into/printing from matrix b. Also, replace 10 with a #define constant that has a sensible name:
    Code:
    #define MAX_SIZE    10
    ...
    int matrix1[MAX_SIZE][MAX_SIZE], matrix1_rows, matrix1_cols;
    int matrix2[MAX_SIZE][MAX_SIZE], matrix2_rows, matrix2_cols;
    Seriously, this will help you immensely. It will make it easy for you and for us to read your code and understand what you are trying to do. The easier it is to read your code, the harder it is for you to make mistakes, and the easier it is for you (and us) to find and fix them. One letter variable names are really only acceptable in a few situations: as a basic loop/array index, or when implementing a mathematical function in which the variable being represented is actually a single letter. Otherwise, your variable names should reflect what the variable is used for.
    Code:
    scanf("%d",&q,&w);
    ...
    scanf("%d",&e,&r);
    Each of those scanf calls only reads in one integer, but you are trying to store it in two integers. If you want the matrix to be a square, read in only one dimension, say matrix1_rows, then simply assign it to matrix1_cols
    Code:
    scanf("%d", &matrix1_rows);
    matrix1_cols = matrix1_rows);
    Or, if you want to support rectangular matrices, you need two %d's in your scanf
    Code:
    scanf("%d%d", &matrix1_rows, &matrix1_cols);
    All your for loops for array access are wrong:
    Code:
    for(i=1;i<=w;i++)
    Recall, in C, arrays start at 0 and go to size-1. The classic for loop idiom for array access starts at 0 and goes until < (not <=) the size:
    Code:
    for (i = 0; i < matrix1_rows; i++)
    You should print some spaces and new lines between the elements of your matrices, so the output is actually readable. Try something like:
    Code:
    for (i = 0; i < matrix1_rows; i++) {
        for (j = 0; j < matrix1_cols; j++) {
            printf("%4d ", matrix1[i][j]);
        }
        putchar('\n');
    }
    Salem likes this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1 Error : Declaration Terminated Incorrectly
    By Inderjeet in forum C++ Programming
    Replies: 7
    Last Post: 07-01-2011, 01:25 AM
  2. bcc 5.5 Declaration terminated incorrectly
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-28-2008, 04:45 PM
  3. error declaration terminated incorrectly help
    By belfour in forum C++ Programming
    Replies: 7
    Last Post: 11-25-2002, 08:07 PM
  4. Declaration terminated incorrectly
    By Griffin2020 in forum C Programming
    Replies: 8
    Last Post: 04-26-2002, 11:53 PM
  5. declaration terminated incorrectly
    By Clane in forum C++ Programming
    Replies: 4
    Last Post: 03-07-2002, 11:09 PM

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