pls help me in this error...urgent

This is a discussion on pls help me in this error...urgent within the C Programming forums, part of the General Programming Boards category; L111 : invalid types for array subscript Code: #include <stdio.h> #include <time.h> #include <math.h> #include <stdlib.h> typedef struct { int ...

  1. #1
    Registered User
    Join Date
    Aug 2011

    pls help me in this error...urgent

    L111 : invalid types for array subscript
    #include <stdio.h>
    #include <time.h>
    #include <math.h>
    #include <stdlib.h>
    typedef struct {
         int x;
    	 int y;
    permute(city *a,int n,int t,int **d,int *b)
      int i,j,temp1,temp2;
    	   (*b) += d[j][j+1];
    	 (*b) += d[j][0];
            temp1 = (a+i)->x;
    		temp2 = (a+i)->y;
            (a+i)->x = (a+(n-1))->x;
    		(a+i)->y = (a+(n-1))->y;
    	    (a+(n-1))->x = temp1;
    		(a+(n-1))->y = temp2;
    	    temp1 = (a+i)->x;
    		temp2 = (a+i)->y;
            (a+i)->x = (a+(n-1))->x;
    		(a+i)->y = (a+(n-1))->y;
    	    (a+(n-1))->x = temp1;
    		(a+(n-1))->y = temp2;
    minimum(int *b, int n)
      int min;
      for(int i=n-2;i<=0;i++)
    	   min = *(b+i);
      printf("Minimum cost for the trip is %d\n\n",min); 
    int main()
    int n;
    printf("How many cities you want to travel (include the starting position ,too, in your number)\n\n");
    city *a;
    a=(city *)malloc(n*sizeof(city));
    printf("\n\nAssume the x and y co-ordinate of the city from where you start(or end) the journey to be (0,0)\n\n");
    printf("Data stored for the city from where you start\n\n");
    printf("Now ,storing x and y co-ordinate of the other cities (random value)\n\n");
    printf("press enter to randomly generate the co-ordinates.....");
    srand((unsigned)time ( NULL ) );
    for(int i=1;i<n;i++)
    (a+i)->x= 0 + rand()%1000;
    (a+i)->y= 0 + rand()%1000;
    printf("\n\nData storing successful for other cities\n\n");
    printf("Now, sorting the cities with respect to their x co-ordinates\n\n");
    printf("press enter to sort the cities......");
    int temp1,temp2;
    for(int j=0;j<n-1;j++)
      for(int k=j+1;k<n;k++)
    	  if((a+j)->x > (a+k)->x)
    		 temp1 = (a+j)->x;
    		 temp2 = (a+j)->y;
    		 (a+j)->x = (a+k)->x;
    		 (a+j)->y = (a+k)->y;
    		 (a+k)->x = temp1;
    		 (a+k)->y = temp2;
    printf("\n\ncities with respect to their x co-ordinate is sorted\n\n");
    int d[n][n];
    printf("calculating the distance between the cities\n\n");
    printf("press enter to calculate and store.....");
    int m,l,g;
         d[l][m] = (int) sqrt(pow(((a+l)->x - (a+m)->x),2) + pow(((a+l)->y - (a+m)->y),2));
         d[l][m] = d[m][l];
    printf("\n\nDistances calculated and stored\n\n");
    int fac,min;
    fac = 1;
       fac *= g;
    fac +=1;
    int *b;
    b =(int *)malloc(fac*sizeof(int));

  2. #2
    Join Date
    Aug 2010
    Ontario Canada
    And on which line of all that code is the error occuring?

    Your compiler's error messages should contain a line number so you can go directly to the offending line....

    Also you should turn your compiler's error and warning levels up to maximum and whatever it prints out should be seen as a problem to be corrected.

    Yes... compiler errors are your friends...

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > permute[a,n,n,d,b];
    > minimum[b,fac];
    If these are an attempt to call YOUR functions, perhaps you should look at how you call all the other functions, like printf.
    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
    May 2011
    Around 8.3 light-minutes from the Sun
    You may find useful information about functions here - Lesson - 4 Functions


    main() returns an int. You failed to do so. The basic C program is:
    int main(void){
         return 0;
    Read about main() here.

    Read about how to indent your code.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help urgent with error!!
    By Tiglet in forum C# Programming
    Replies: 5
    Last Post: 03-14-2010, 04:42 PM
  2. Replies: 1
    Last Post: 12-19-2008, 05:32 AM
  3. Replies: 2
    Last Post: 05-28-2007, 12:06 AM
  4. last line error, URGENT
    By deng17 in forum C++ Programming
    Replies: 7
    Last Post: 03-25-2007, 06:45 AM
  5. unknown error, urgent help needed
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-30-2003, 05:09 AM

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