2 Replies - 670 Views - Last Post: 24 September 2016 - 08:39 AM Rate Topic: -----

#1 Satabios  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 18
  • Joined: 28-August 14

Pointer explanation and help required!

Posted 24 September 2016 - 07:03 AM

I'm building a small program that takes english as input and give the equivalent morse values.
For which I declared a set of values that is to be used during the morse equivalent represenation.
And I get few errors which I'm posting here.



// global variables
 int i=0;
char pattern[6];
char english[50];

 char *final_string[50];
char fin[40];
int index=0;

#define NUM_CODES (32)
#define NUM_WORDS (32)
#define NUM_ABB   (33)
int abb_flag=0;
  
static const char *codes[NUM_CODES] = {".....","....-","...-.","...--","..-..","..-.-/>/>","..--.","..---",
                                       ".-...",".-..-",".-.-/>/>.",".-.-/>/>-",".--..",".--.-/>/>",".---.",".----",
                                       "-....","-...-","-..-.","-..--","-.-/>/>..","-.-/>/>.-","-.-/>/>-.","-.-/>/>--",
                                       "--...","--..-","--.-/>/>.","--.-/>/>-","---..","---.-/>/>","----.","-----"
                                                                             
                                       };

static const char *words[NUM_CODES] = {".","A","B","C","D","E","F","G",
                                       "H","I","J","K","L","M","N","O",
                                       "P","Q","R","S","T","U","V","W",
                                       "X","Y","Z","?","0","1","2","4"
                                       };
--------------------------------

----------------------
----------
---
----
-
-
-
-
-
-
-
-
--
-
-
-
-
-
-
----
void findletter() {
  int k;
  
  // go through all the codes  
  for(k=0;k<NUM_CODES;k++) {
    // check if code[i] matches pattern exactly.
    if(strlen(pattern) == strlen(codes[k]) && strcmp(pattern,codes[k])==0) {
      // match!

        if(*words[k]=='.'){
      //  fin[0]=*final_string[0];
        
       // fin[1]=*final_string[1];
        
       // fin[2]=*final_string[2];
         chk_abb();
      
       // Serial.println(final_string);
       
   
              
      }
      
      else {
      Serial.print(' ');
      Serial.println(words[k]);
      
    
    
      *final_string[index]=*words[k];              // line 162
/*     
  error: invalid types 'char* [50][char*(const char*, int)]' for array subscript
sketch_sep21a.ino:163:18: error: invalid types 'char [40][char*(const char*, int)]' for array subscript
sketch_sep21a.ino:163:40: error: invalid types 'char* [50][char*(const char*, int)]' for array subscript
sketch_sep21a.ino:165:9: error: ISO C++ forbids incrementing a pointer of type 'char* (*)(const char*, int)' [-fpermissive]
sketch_sep21a.ino:165:9: error: lvalue required as increment operand
*/
        fin[index]= *final_string[index]          // line 163
      
      ++index;                                    // line 165
      
      
    
      
      i=0;
      
     
         }
    }
  
  }
}

void chk_abb(){

    int k;
  
  // go through all the codes  
  for(k=0;k<NUM_ABB;k++) {
    // check if code[i] matches pattern exactly.
    if(strlen(fin) == strlen(abb[k]) && strcmp(fin,abb[k])==0) {
      // match!
      Serial.print(' ');
      Serial.println(full_form[k]);


       //tts the abb;
      
        flag=1;      
      }
  }

      if(flag==0) {
        //tts the sentence
      }
  
    
      index=0;                    // line 203

/*
error: assignment of function 'char* index(const char*, int)'
sketch_sep21a.ino:203:12: error: cannot convert 'int' to 'char*(const char*, int)' in assignment */
     
    
  
  
}





I tried to change the finalstring as a normal char data type rather then having a pointer one , still errors
prevail. I've tried many but failes, If someone could pointed me out and explain whats the wrong I'm making here it would be gratefull.

Any suggestions are arppreciated.
Thanks.

-SH

Is This A Good Question/Topic? 0
  • +

Replies To: Pointer explanation and help required!

#2 andrewsw  Icon User is offline

  • lashings of ginger beer
  • member icon

Reputation: 6336
  • View blog
  • Posts: 25,545
  • Joined: 12-December 12

Re: Pointer explanation and help required!

Posted 24 September 2016 - 07:06 AM

Question moved out of Discussion Lounge. You are seeking help with a problem not initiating a discussion.
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon

Reputation: 5296
  • View blog
  • Posts: 16,508
  • Joined: 25-December 09

Re: Pointer explanation and help required!

Posted 24 September 2016 - 08:39 AM

A few questions about your code.

First what language are you trying to learn? What is a Serial?

Second why all the horrible global variables?

If you're trying to learn C++ then why all the C-strings? You would be much better off using std::string instead.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1