Thread: Parse Error - Need help fast

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    3

    Parse Error - Need help fast

    I know. Waiting until the last minute to ask for help is not a good idea. I have been working on this assignment all week and thought I had it all figured out. Now I have a parse error that I just can't figure out. I am brand new to programming. Any help would be appreciated.

    Here is the error message:

    Code:
    c:\program files\miracle c\week5.c: line 19: Parse Error, expecting `SEP'
    '{ int array[8]'
    aborting compile
    Here is my program:

    Code:
    /*this program asks user for eight integers and then sorts them into ascending order*/
    
    #include <stdio.h>
    int main(int argc, char *argv[])
    
    {
      int index;
      int array[8];				/*this array has 8 integers*/
    
      for(index = 0; index < 8; index++)
      {
        printf("Enter eight intergers to be sorted.\n");
        scanf("%d", array[index]);		/*get integers from user*/
      }
    }
    
    {
      int array[8];				/*identifies the array*/
      int i, j, k, x;
     
      for(i = 0; i < 8; i++)
      {
        if (array[i] > array[j])
        {
          x = array[i];
          array[i] = array[j];
          array[j] = x;
        }
      }
    
      for(k = 0; k < 8; k++)
      {
        printf("%d", array[k]);
        printf("\n");
      }
    }
    return 0;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    }
    /* Notice anything missing? */
    {
    I know, I'm breaking my 24-hour rule here, but I'm feeling generous today.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    you are using too many brackets on your main function, after the scanf, you need to remove 1 closing bracket. you are also using j without being initalized.

    edit:
    When no one helps you out. Call google();

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I just figured they were making another function and leaving out the return value for main. But I see it's just all around ugly instead.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    184
    here are some of the things which i think un wanted

    Code:
    #include <stdio.h>
    int main([color]int argc, char *argv[][/color])
    
    {
      int index;
      int array[8];				/*this array has 8 integers*/
    
      for(index = 0; index < 8; index++)
      {
        printf("Enter eight intergers to be sorted.\n");
        scanf("%d", array[index]);		/*get integers from user*/
      }
    [color]}[/color]
    
    [color]{[/color]
      int array[8];				/*identifies the array*/
      int i, j, k, x;
     
      for(i = 0; i < 8; i++)
      {
        if (array[i] > array[j])
        {
          x = array[i];
          array[i] = array[j];
          array[j] = x;
        }
      }
    
      for(k = 0; k < 8; k++)
      {
        printf("%d", array[k]);
        printf("\n");
      }
    
    Code:
    }
    return 0; } and here is the working programe
    Code:
    #include <stdio.h>
    
    int main()
    {
      int index;
      int array[8];				/*this array has 8 integers*/
      int i, j, k, x;
      
      printf("Enter eight intergers to be sorted.\n");
      for(index = 0; index < 8; index++)
      {
            scanf("%d", &array[index]);		/*get integers from user*/
      }
     
      for(i = 0; i < 8-1; i++)
      {
          for(j=i+1;j<8;j++)
        if (array[i] > array[j])
        {
          x = array[i];
          array[i] = array[j];
          array[j] = x;
        }
      }
    
      for(k = 0; k < 8; k++)
      {
        printf("%d\t", array[k]);
        printf("\n");
      }
    getchar();
    return 0;
    }
    s.s.harish

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    3
    How's this? I am still getting the parse error though. I highlighted in red the line of programming that is confusing me.

    Code:
    /*this program asks user for eight integers and then sorts them into ascending order*/
    
    #include <stdio.h>
    int main(int argc, char *argv[])
    
    {
      int index;
      int array[8];				/*this array has 8 integers*/
    
      for(index = 0; index < 8; index++)
      {
        printf("Enter eight intergers to be sorted.\n");
        scanf("%d", array[index]);		/*get integers from user*/
    }
    
    {
    [red]  &array[index];  [/red]
      int i, j, k, x;
     
      for(i = 0; i < 8; i++)
      {
        if (array[i] > array[j])
        {
          x = array[i];
          array[i] = array[j];
          array[j] = x;
        }
      }
    
      for(k = 0; k < 8; k++)
      {
        printf("%d", array[k]);
        printf("\n");
      }
    }
    return 0;
    }

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    Try understanding the code ssharish posted he corrected your program so it works. with that said you should look up how scanf works, and how how nested loops work.

    good luck and dont give up.
    When no one helps you out. Call google();

  8. #8
    Registered User
    Join Date
    Mar 2005
    Posts
    3
    You are a life saver!!! Seeing the corrected version really helped clear up where I was screwing it all up. I thought that for every opening bracket, I had to have a closing bracket. I had also figured out how to build the array and had a sample from the instructor on how to sort a fixed array, but didn't know how to put them together. The program works now with no parse errors. Thank you for your help.

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    &array[index];
    What in the world is that line of code supposed to do? If you take out that line, your code should compile OK. This of course doesn't address the semantic errors in your program, but at least it will compile.
    Last edited by bithub; 03-02-2005 at 08:47 PM.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You mean aside from the fact that neither of you know how to use color tags correctly.

    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    184
    Very Sorry About The Color Code Tag

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's no problem. For an example of how they work, when you create a post, there's a drop down list of colors. (Those are just a few sample ones). Click on one, and you'll see how they work. Basicly it's:

    [color=colorname] ...stuff here... [/color]

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM