Storing Characters in EEPROM

So i'm taking a class where we are using the arduino Uno to do some basic stuff and I have zero experience with C programming. Can anyone help me out or help me understand this? Basically I'm given a code thats missing some segments, and I have to fill in these segments to get the program to work.

// Lab 8 - Exercise 1
#include <EEPROM.h>
int addr=0, maxChars=10;
char ch;

void setup() {
 Serial.begin(9600); 
}

void loop() {
  if(Serial.available()) {
    ch = Serial.read();
    if (ch == '0') {
      clear();
    } else {
      if(addr <maxChars) {
        //#Code missing to write values to memory
      }
    }
  } else {
    displayOutput();
    delay(5000);
  }
}

void clear() {
 //#Code missing  to clear EEPROM
 Serial.println("EEPROM cleared");
}

void displayOutput() {
   for(int i=0; i<maxChars; i++) {
    char storedVal = EEPROM.read(i);
    Serial.print("Memory Location ");
    Serial.print(i);
    Serial.print(" : ");
    Serial.print(storedVal);
    Serial.print("\n");
    }
  Serial.println("#######\n"); 
}

Did you look at the eeprom library page?

It's pretty straightforward. The code you provided already uses one of the commands even.

If you have zero experience then I would have thought that you might read the how to use the forum sticky post and learn how to post your code correctly.

So how do you define work and do we get marks for doing your homework for you?

Grumpy_Mike:
If you have zero experience then I would have thought that you might read the how to use the forum sticky post and learn how to post your code correctly.

So how do you define work and do we get marks for doing your homework for you?

I guess theres a reason they call you grumpy mike

I see two comments indicating missing code.

Do you understand what the overall sketch is intended to do when it's complete?

Do you know what is supposed to happen in each of those sections in order to achieve that?

Sharkbiteattack:
I guess theres a reason they call you grumpy mike

See that number next to the green + sign next to Grumpy_Mike's post? That's the number of times people have gone out of the way to thank him for help he's given. I don't know whether there are any people here who have received more thanks, but there can't be many; Grumpy_Mike is one of the most helpful people here. Although perhaps he might make an exception in your case, given the rudeness of your reply.

Although perhaps he might make an exception in your case, given the rudeness of your reply.

I took it as being funny. You should expect someone like Grumpy_Mike to let you know when you forgot to do your homework...

Sharkbiteattack maybe this will be some help, I don't know as I am still trying to finger things out... I have been trying to figure out the 24C04 stuff but so far I'm just pulling my hair out. ACK!

Sharkbiteattack:
I guess theres a reason they call you grumpy mike

Who are "they". It is a name I selected myself the same as the name you selected.

We are good here at helping people there are lots of satisfied users. What we are not good at is being taken advantage of. You posted something that looks like your homework, so we will help you learn but most people will not do it for you. Yes I could easily do the problem for you but that gets no one anywhere. You learn nothing and I get to prove I can do something simple. Anyway good marks for changing the posting so that the code is formatted correctly. :slight_smile:

Now you want to get clear in your mind exactly what you want the code to do.
Saving and reading a byte to EEPROM is easy, you need to know what the byte is and where in the EEPROM you want to store it. Storage locations are just numbers, so start with zero and add one each time you store something. To do that you put the address, for that is what we call it, into a variable.

Just to make it clear, EEPROM.write() takes an address (where to write) and a byte (the value to write). Now, fortunately for you, bytes and chars are exactly the same size, so you can use EEPROM.write() to write a char, without having to resort to splitting the char up into its constituent bytes.