1

I know this is not a good question. But I am clueless with this error : invalid array assignment (at function convert). For extra information, I involved a lot of copying/pasting programs I haven't exactly understand from internet in the convert function (the strncpy ones) so.. yeah.

This is the program I've done (the menu/mn button currently not used):

#include <LiquidCrystal.h>
#define WORD 11
#define LETTER 15
LiquidCrystal lcd(7,6,5,4,3,2);
int i=0;
char input[] = "a";
char output[15];
const int dw = 8;
const int ri = 9;
const int le = 10;
const int up = 11;
const int ok = 12;
const int mn = 13;
int checker = 0;
int bounceCk = 0;

int bdw=0, bri=0, ble=0, beu=0, beo=0, bem=0;

void setup()
{
  pinMode(dw, INPUT);
  pinMode(ri, INPUT);
  pinMode(le, INPUT);
  pinMode(up, INPUT);
  pinMode(ok, INPUT);
  pinMode(mn, INPUT);  
}
void intext()
{
  int lim=16;
  lcd.setCursor(0,1);
  lcd.print(input);
  for(i=0; i<lim ; )
  {
    lcd.setCursor(0,1);
    lcd.print(input);  
    if(digitalRead(dw)==HIGH)
    {
      checker=digitalRead(dw);
      delay(100);
      bounceCk=digitalRead(dw);
      if(checker==bounceCk)
      {
        if(input[i]>'z')
          input[i]='a';
        input[i]=input[i]+1;
      }      
    }
    if(digitalRead(up)==HIGH)
    {
      checker=digitalRead(up);
      delay(100);
      bounceCk=digitalRead(up);
      if(checker==bounceCk)
      {
        if(input[i]<'a')
          input[i]='z';
        input[i]=input[i]-1;    
      }
    }
    if(digitalRead(ri)==HIGH && i<16)
    {  
      checker=digitalRead(ri);
      delay(100);
      bounceCk=digitalRead(ri);
      if(checker==bounceCk)
      { 
        i=i+1;
      }
    }
    if(digitalRead(le)==HIGH && i>0)
    {
      checker=digitalRead(le);
      delay(100);
      bounceCk=digitalRead(le);
      if(checker==bounceCk)
      {      
        i=i-1;
      }
    }
    if(digitalRead(ok)==HIGH)
    {
      checker=digitalRead(ok);
      delay(100);
      bounceCk=digitalRead(ok);
      if(checker==bounceCk)
      {      
        lim=i;
      }
    }
  }
}
void convert()
{
   char sumber[WORD][LETTER] = {{0}};  /* declare a progmem unsigned static array of kata x huruf */
   char dasar[WORD][LETTER] = {{0}};  /* declare a progmem unsigned static array of kata x huruf */

  /* copy various strings to statically declared storage SUMBER */
  strncpy (sumber[0],"memakan", strlen("memakan")+1);
  strncpy (sumber[1],"makanan", strlen("makanan")+1);
  strncpy (sumber[2],"menyuci", strlen("menyuci")+1);
  strncpy (sumber[3],"perubahan", strlen("perubahan")+1);
  strncpy (sumber[4],"penulisan", strlen("penulisan")+1);
  strncpy (sumber[5],"tercampurkan", strlen("tercampurkan")+1);
  strncpy (sumber[6],"pengelompokan", strlen("pengelompokan")+1);
  strncpy (sumber[7],"pengembangan", strlen("pengembangan")+1);
  strncpy (sumber[8],"kehebatan", strlen("kehebatan")+1);
  strncpy (sumber[9],"memotret", strlen("memotret")+1);
  strncpy (sumber[10],"melakukan", strlen("melakukan")+1);

  /* copy various strings to statically declared storage DASAR*/
  strncpy (dasar[0],"makan", strlen("makan")+1);
  strncpy (dasar[1],"makan", strlen("makan")+1);
  strncpy (dasar[2],"cuci", strlen("cuci")+1);
  strncpy (dasar[3],"ubah", strlen("ubah")+1);
  strncpy (dasar[4],"tulis", strlen("tulis")+1);
  strncpy (dasar[5],"campur", strlen("campur")+1);
  strncpy (dasar[6],"kelompok", strlen("kelompok")+1);
  strncpy (dasar[7],"kembang", strlen("kembang")+1);
  strncpy (dasar[8],"hebat", strlen("hebat")+1);
  strncpy (dasar[9],"potret", strlen("potret")+1);
  strncpy (dasar[10],"laku", strlen("laku")+1);

    /* mencari input pada sumber */
  int k=0, search=0, sel=9;

  while(search==0)
  {
    sel=strcmp(input, sumber[k]);
    if(sel==0)
    {
      output[]=dasar[k]; //!!!!THE ERROR IS HERE!!! happen to either this or output=dasar[k]
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Base Word:");
      lcd.setCursor(0,1);
      lcd.print(output);      
      search=1;
    }
    else
    {
      k=k+1;
      if(k>=11)
      {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Error:NF");
        lcd.setCursor(0,1);
        lcd.print("word n found");
        search=1;
      }
    }
  }
    /* 
    //print the values 
    while (*sumber[i])
        printf ("  %s\n", sumber[i++]);
    */

}  
void loop()
{
  lcd.begin(16,2);
  lcd.setCursor(0,0);
  lcd.print("Type your word:");
  intext();
  convert();
  delay(15000);
}

I found more errors before, I've fixed those, but can't fix this one. I think this problem is caused by the wrong instruction or wrong format. But can't found solution...yet.

The program is converting words to its basic word in Bahasa, you can compare it to English like this. You type "eaten" and it will return "eat". You type "understood" it will return "understand". When you type "stunk" it will return "stink". Or something like that.

Example in bahasa :

"memakan" (eating) -> "makan" (eat)

"makanan" (food) -> "makan" (eat)

"pengembangan" (development) -> "kembang" (becoming bigger/better)

etc

I hope someone will give me a clear hint or two (I'm not too bright, but I still need to learn how not just copying things around), Thank you very much!

1

It looks like you're trying to copy the contents of a particular sub-array in dasar across to the output array. However, this isn't valid in C/C++:

output[]=dasar[k];

To copy data from one array to another, you either need to copy each element one-by-one (e.g. in a loop), or use a block memory operation like memcpy.

Here's how I would do it:

memcpy(output, dasar[k], sizeof(output));

This should work because arrays are basically just pointers in C/C++. It uses the start of output as the destination of the copy, and uses the start of dasar[k] as the source. The number of bytes it copies is taken from the total size of the output array.

4
  • So the sizeof(output) means we can use it like this sizeof(strlen(output)) ? Thank you! – Febri Kurniawan Jan 17 '15 at 5:05
  • No, sizeof(strlen(output)) doesn't make any sense. It would give you the size (in bytes) of the value returned by strlen(), which has nothing to do with the contents of output. Assuming the string stored in output is properly null-terminated, simply strlen(output) should tell you how many characters it actually uses. – Peter Bloomfield Jan 17 '15 at 5:16
  • The program above (at the question) will not make any null characters (I guess?)... and after some reading I think I got that sizeof is kind of like strlen, except it's counting any type of data? So it is interchangeable (as those string isn't null terminated?) with strlen? But now I got it clearly about memcpy. Thank you, thank you very much for your help. really thank you. – Febri Kurniawan Jan 18 '15 at 3:34
  • Your strncpy operations are adding the null terminators by copying them out of the string literals (string literals are implicitly null-terminated in C/C++). sizeof isn't equivalent to strlen though. sizeof gives you the size of any object, variable, or static array in bytes. strlen is only for strings, and it keeps counting characters until it reaches a null character (even if that means it goes past the end of an array). – Peter Bloomfield Jan 18 '15 at 10:56
0

Just replace the line in error with:

strcpy(output, dasar[k]);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.