Thread: error: expected primary-expression before string ‘teee’

  1. #1
    Registered User
    Join Date
    Aug 2018
    Posts
    5

    error: expected primary-expression before string ‘teee’

    Hello coding community,
    The code below is a variation on the run-length encoding but adapted for my hex string. The code is supposed to take the string and put a space between every two characters eg "3030" becomes "30 30" and puts the output of that into bytes vector and from that into the array. Now, it will place an array element into the temphexholder array and check if the next array element of databytes is the same as the element in temphexholder it will increment counter if not it will append counter and databytes to runlengthengthcoding string. So the result is eg. : original string: "303030304040" becomes "30044002". However when I try to use the function it gives me the error in the title
    Code:
    string integerrunlengthencoding(string hextext) {
        //string hextext = "";
        int counter,a;
        unsigned char temphexholder[1];
        cout << hextext ; 
        int length = hextext.size();
            string output = "";
        string runlengthengthcoding = "";
     
            //for each block of 2 characters
            for(int i =0 ; i< length; i=i+2)
            {
            //copy 2 characters and a space to the output
            output += hextext.substr(i, 2) + " ";
     
            }
        std::istringstream hex_chars_stream(output);
        std::vector<unsigned char> bytes;
        unsigned int c;
        unsigned char databytes[52]; // 52 data bytes
        while (hex_chars_stream >> std::hex >> c)
        {
                bytes.push_back(c);
            
        }
        for(int q=0;q<52;q++){ 
            databytes[q] = bytes[q]; 
            
        }    
        for(int w=0;w<52;w++){
            
            if(temphexholder[0] == databytes[w]){
                counter++;        
            }
            if(temphexholder[0] != databytes[w]){
                runlengthengthcoding += databytes[w] + counter;    
                counter = 0;
                temphexholder[0] = databytes[w];
            }
            
        }
        return runlengthengthcoding;
    }
    
    int main (){
    string teee = "303040505050efef30454540404040405050502021212123232345562929293445232334458939414123232323232323456789";
        
        cout << teee;    
        cout  << "The compressed string becomes: " << integerrunlengthencoding(string teee);
    }   // why is this not working
    Last edited by ikhram; 1 Week Ago at 08:50 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,194
    What headers are you #including? Also how are you scoping things in the std:: namespace?

    Code:
        unsigned char temphexholder[1];
    Why the array? IMO, this will just be confusing and will probably lead to out of bounds access of this "array", you would be better just using a single instance instead of the array.

  3. #3
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    709
    Code:
    cout  << "The compressed string becomes: " << integerrunlengthencoding(string teee);
    You called your function as function(string variable); when it should be function(variable);.

    I would also suggest you start using references (&) and const, since you're already writing programs of a certain complexity.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [15]error: expected primary-expression before '<'
    By hutkikz in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2015, 03:36 PM
  2. ATM C++ ERROR *expected primary expression before else*
    By GrafixFairy in forum C++ Programming
    Replies: 1
    Last Post: 03-29-2014, 10:31 AM
  3. error : expected primary-expression before ']' token
    By funnydarkvador in forum C Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  4. error : expected primary-expression before ']' token
    By funnydarkvador in forum C++ Programming
    Replies: 8
    Last Post: 02-20-2013, 07:06 PM
  5. Error: expected primary expression and ; before else
    By dragonfly22 in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2012, 04:24 PM

Tags for this Thread