| | |
C++: compile error "subscripted value is neither array nor pointer"
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
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:
in regards to these lines:
it is declared correctly, like this:
what error is that???? anyone?
everything was compiling fine, until i put the thread implementation in ....
all of a sudden, it gives me this:
C++ Syntax (Toggle Plain Text)
-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:
C++ Syntax (Toggle Plain Text)
32: n[x] = atoi(readnum); 33: printf("%i ", n[x]);
it is declared correctly, like this:
C++ Syntax (Toggle Plain Text)
const int MAX = 1024; int n[51]; int tot_n; void *numsort (void *arg); int main() { char readnum[MAX]; . . .
what error is that???? anyone?
•
•
Join Date: Oct 2004
Posts: 31
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Narue
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.
C++ Syntax (Toggle Plain Text)
const int MAX = 1024; int nums[50]; int tot_n;
my locals:
C++ Syntax (Toggle Plain Text)
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:
C++ Syntax (Toggle Plain Text)
-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
C++ Syntax (Toggle Plain Text)
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.
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.
I'm here to prove you wrong.
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[i]);
}
printf("%d\n", StoreID[i]);
return StoreID[i];
}
In function 'main':
15: Warning: passing argument 2 of 'GetID' makes pointer from integer without a cast.
#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[i]);
}
printf("%d\n", StoreID[i]);
return StoreID[i];
}
In function 'main':
15: Warning: passing argument 2 of 'GetID' makes pointer from integer without a cast.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Little help with gcc & gdb
- Next Thread: Message Handler In C++ Builder ?
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





