Pointers Access Operators in Arduino Environment

Hello,

I am trying to implement the code found below and I keep getting the following error:
Arduino: 1.0.5 (Mac OS X), Board: "Arduino Diecimila or Duemilanove w/ ATmega168"
sketch_sep22a.ino: In function 'String whatup()':
sketch_sep22a:23: error: cannot convert 'String' to 'String*' in assignment
sketch_sep22a:25: error: conversion from 'String*' to non-scalar type 'String' requested

Could you help me understand why this is happening?

Thanks,
Victor

String fret[6] [4] = {  {"G", "F#/Gb", "F", "E"},
                        {"C", "B", "A#/Bb", "A"},
                        {"F", "E", "D#/Eb", "D"},
                        {"A#/Bb", "A", "G#,Ab", "G"},
                        {"D", "C#/Db", "C", "B"},
                        {"G", "F#/Gb", "F", "E"}  };


void loop () {

String one;

one = whatup(); //victor value is stored into one.
Serial.println(one);  // should print memory location of fret [0] [2]
  
  
}

String whatup(){  

String *victor; // Set up pointer
victor = fret [0] [2]; // Stores memory location 

return victor; // return pointer 
}

vmesparz:
Hello,

I am trying to implement the code found below and I keep getting the following error:
Arduino: 1.0.5 (Mac OS X), Board: "Arduino Diecimila or Duemilanove w/ ATmega168"
sketch_sep22a.ino: In function 'String whatup()':
sketch_sep22a:23: error: cannot convert 'String' to 'String*' in assignment
sketch_sep22a:25: error: conversion from 'String*' to non-scalar type 'String' requested

Could you help me understand why this is happening?

the error message says it all - your trying to return a String * and use it as a String - exactly what are you trying to achieve here? you've got some fundamental issues in the code based on what is written vs what is in the comments. do you want to show the string, or the address of the string?

Thank you for looking at this.

I am trying to display the address of the display.

the address of the string?

String fret[6] [4] = {  {"G", "F#/Gb", "F", "E"},
                        {"C", "B", "A#/Bb", "A"},
                        {"F", "E", "D#/Eb", "D"},
                        {"A#/Bb", "A", "G#,Ab", "G"},
                        {"D", "C#/Db", "C", "B"},
                        {"G", "F#/Gb", "F", "E"}  };

void loop () 
{
  int one;
  one = whatup(); //victor value is stored into one.
  Serial.println(one);  // should print memory location of fret [0] [2]
 }

int whatup()
{  
String *victor;
victor = &fret [0] [2]; 
return (int)victor; // return address 
}

a memory address is really just an integer.

Yes - I meant the address of the String.

Thank you - that fixed it. :slight_smile: