reading a certain location in a string

Hello,

I have migrated from basic to C and have a problem with string manipulation.

The following code is suppose to read a byte from a string and write it in decimal to eeprom in sequence.

However, "val was not declared in this scope" error message is preventing me to do so.

Help is required. Thank you in advance.

// this routine writes parameter values into eeporom
#include <EEPROM.h>

char *seq1 = "0000001100101110";
int sayac;
int x;

void setup()
{
 for (sayac = 0; sayac < 15; sayac += 1)
 {
    x = val(seq1, sayac);
    EEPROM.write(sayac, x);
 }
}

void loop()
{
}

So, where is val declared in ANY scope? You can't call non-existent functions.

val is supposed to mean "value of" as in basic language.

I haven't spoken BASIC for a very long time, but did you mean
x = seq1 [sayac]; ?

(I think the syntax of arrays in BASIC is very similar)

Atari400:
val is supposed to mean "value of" as in basic language.

as you have noticed this is not BASIC
Try using

 x = seq[sayac] & 0xf;

If you want to recover the individual value of one digit from a string of digits.
However this is very wasteful as you are using 8 bytes to hold what is just a one byte number.

True. I guess I was lost trying to convert a string into a decimal.

It works now.

Thanks.

p.s. Grumpy_Mike: I'm aware that is is C. However, I did mention that in my 1'st post. Thanks anyway.

As PaulS points out, there is no "standard library" function named val(), so you must write your own. While I'm not sure what you're trying to do, given the name of the missing function, it appears that you are trying to store the individual values in the seq1 array in EEPROM. If that's the case, look at the following:

// this routine writes parameter values into eeporom
#include <EEPROM.h>

char *seq1 = "0000001100101110";
int sayac;
int x;

void setup()
{
  Serial.begin(9600);
  
 for (sayac = 0; sayac < 15; sayac += 1)
 {
    x = val(seq1, sayac);
    
    Serial.print("x = ");
    Serial.println(x);
    
    //EEPROM.write(sayac, x);
 }
}

void loop()
{
}

/*****
   Function that returns a byte value for a character passed to it.

 Parameters:
   char *array    A pointer to the character array
   int index       The element in the array of interest

 Return value:
   byte
*****?
byte val(char *array, int index)
{
  byte b;
  
  b = (byte) *(array + index) - '0';

  return b;
}

When the function val() is called, you pass to it the starting address of the seq1 array of characters. Because it is an array, you could make the first line of the function as shown, or as you could write the function as:

byte val(char array[], int index)
{
  byte b;
  
  //b = (byte) *(array + index) - '0';
  b = (byte) array[index] - '0';

  return b;
}

The code performs the same because of the way pointers work relative to array data definitions. The expression "- '0'" at the end of the one statement converts the byte character being read from the array into an integral value. The character zero ('0') has an ASCII value of 48. If you didn't make the adjustment, you'd get:

b = (byte) array[index];
b = (byte) array[0];
b = (byte) 48;
b = 48;

which makes the value 48. Since I'm assuming val() should return an integral value, not a character value, I subtracted '0' from each numeric character read in the for loop:

b = (byte) array[index] - '0';
b = (byte) array[0] - 48;
b = (byte) 48 - 48;
b = 0;

which stores the integral value 0 in EEPROM.