GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Jun-2012, 15:54
casprandel casprandel is offline
New Member
 
Join Date: Jun 2012
Posts: 2
casprandel is on a distinguished road

Expected primary expression before the ']' token.


This is a basic sequential search of a randomly generated array. I keep getting errors on it. I want to get this working, then I will change the search to make it recursive for my actual assignment... one step at a time. I'm having quite a lot of problems with the class lately especially when it comes to templates. Any help would be much appreciated. If I've failed to give you any information please let me know. I'm not using a header file since the program is very simplistic... I'm sure I'm missing something very small and silly.. at least I hope I am.

CPP / C++ / C Code:
#include <cstdlib>
#include <iostream>

using namespace std;

template <class elemType>
int seqSearch(const elemType list[], int length, const elemType& item);

int main(int argc, char *argv[])
{
   srand(time(NULL));
   
   int length = 50;
   int i = 0;
   int list[length];
   int item = 25;
   
   //POPULATES THE ARRAY WITH RANDOM NUMBERS
   for(i = 0; i < length; i++)
         list[i] = rand() %100 +1;
         
    //SEARCHES THE ARRAY
    seqSearch(list[], length, item);

    system("PAUSE");
    return EXIT_SUCCESS;
}
template <class elemType>
int seqSearch(const elemType list[], int length, const elemType& item){
    
    int loc;
    bool found = false;
    
    loc = 0;
    
    while (loc < length && !found)
          if (list[loc] == item)
             found = true;
          else
              loc++;
    
    if (found)
       return loc;
    else
        return -1;
}


I can't get it to compile. It gives me the error on line 24 - Expected primary-expression before ']' token
  #2  
Old 03-Jun-2012, 17:41
casprandel casprandel is offline
New Member
 
Join Date: Jun 2012
Posts: 2
casprandel is on a distinguished road

Re: Expected primary expression before the ']' token.


Thanks for your help. Guess I just needed a little more time. Figured it out.
 
 

Recent GIDBlogMatch IP in CIDR by gidnetwork

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Expected primary expression before ')' token bedwar14 C++ Forum 5 27-Nov-2011 22:50
error: expected primary-expression before ‘>’ token Blake C++ Forum 1 29-Mar-2011 09:26
storing a token pointer as a string CoreLEx C Programming Language 1 07-Oct-2003 11:33

Network Sites: GIDNetwork · GIDApp · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:20.


vBulletin, Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.