im compiling a basic sorting algorithm that utilizies POSIX threads (pthreads) ....

everything was compiling fine, until i put the thread implementation in ....

all of a sudden, it gives me this:

-bash-2.05b$ gcc project4a.c -lpthreads
project4a.c: In function `main':
project4a.c:32: subscripted value is neither array nor pointer
project4a.c:33: subscripted value is neither array nor pointer

in regards to these lines:

32:      n[x] = atoi(readnum);
33:      printf("%i ", n[x]);

it is declared correctly, like this:

const int MAX = 1024;
int n[51];
int tot_n;

void *numsort (void *arg);


int main()
{
  char readnum[MAX];
.
.
.

what error is that???? anyone?

n is a highly suspect name for a global variable. Did you accidentally declare a local variable n that was not an array? The global n would be hidden by the local n and you would get that error.

n is a highly suspect name for a global variable. Did you accidentally declare a local variable n that was not an array? The global n would be hidden by the local n and you would get that error.

no, the only global variables i have are:

const int MAX = 1024;
int nums[50];
int tot_n;

my locals:

char readnum[MAX];
  int x = 0;
  int i, j, k, l, m, n;
  char *ifEOF;
  int numof_stgs;
  int numof_threads;
  pthread_t threadID;
  void *thread_result;

i changed it since, and it worked...

but then, now im getting the error again elsewhere:

-bash-2.05b$ gcc project4a.c -lpthread
project4a.c: In function `numsort':
project4a.c:102: warning: assignment makes integer from pointer without a cast
project4a.c:104: invalid operands to binary -
project4a.c:108: array subscript is not an integer
project4a.c:110: array subscript is not an integer
project4a.c:111: array subscript is not an integer
93:  void *numsort(void *arg)
94:  {
95:  
96:    //compare and switch if needed
97:  
98:    int *index = (int*)arg;
99:  
100:    int last, tmp, next;
101:  
102:    next = index + 1;
103:  
104:    last = tot_n - index;
105:  
106:    if (last == 2)
107:      {
108:        if (nums[index] > nums[next])
109:          {
110:            tmp = nums[index];
111:            nums[index] = nums[next];
112:            nums[next] = tmp;
113:          }
114:      }
115:    else
116:      {
117:        printf("checking last element\n");
118:      }
119:  
120:    printf("\n%i: Hello World!\n", arg);
121:  
122:    pthread_exit ((void*)NULL);
123:  }

>no, the only global variables i have are
Those are different from your first post.

>my locals:
I see an n that's declared as int.

>next = index + 1;
This line is trying to compute an offset from index and assign it to next, but next is not a pointer.

>last = tot_n - index;
Subtracting a pointer from an integer makes no sense.

>if (nums[index] > nums[next])
index is a pointer, not an integer. Array indices must be integral.

>tmp = nums[index];
This is the same problem.

>nums[index] = nums[next];
And here as well.

well, that solved it.... im new to the whole pthreads ... i coerced the passed value wrong... needed to coerce it to int, which is what i thought i was doing ....

but now it works ...... thanks for the help!

I am so lost. I don't know what I'm doing. Can somebody help me? What I'm trying to do right now is just store ID numbers in an array to use them elsewhere in my program. I can't even do that right though. This is my first time taking computer science and I just don't get it.

#include <stdio.h>
#include <stdlib.h>


int GetID( int students, int StoreID[41], int i);


int main(void)
{
int students;
int StoreID[41];
int i;


printf("Enter the number of students in the class:");
scanf("%d", &students);


GetID(students,StoreID[],i);


return EXIT_SUCCESS;


}



int GetID( int students,int StoreID[41], int i)
{


printf("Student\n");


for( i=0; i<students; i++)
{
printf("Enter student%d ID:", i+1);
scanf("%d", &StoreID);


}


printf("%d\n", StoreID);


return StoreID;


}
In function 'main':
15: Warning: passing argument 2 of 'GetID' makes pointer from integer without a cast.

Don't go hijacking other people's threads. I already answered your question in your previous thread.

Big deal. I'm new to this site, ok?

So kid, try to be modest instead acting smart. This kind of attitude won't fetch you any help.

Thread closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.