Code:
for(i = 0; i <= lim-1 && (c = getchar()) != EOF && c != '\n'; ++i)
Like the above users have mentioned, what this function is read "characters" (using getchar()) and store them temporarly in var "c". The loop will keep going untill a) the limit (as passed to the function) is reached or b) EOF is reached (Ctrl-D in windows, etc) or finally c) a new line (user pressed 'Enter').
Basically, it reads a number of characters (dictated by lim) untill either EOF or newline is reached. The reason c is an int and not a char, is to be able to trap EOF, which doesn't "fit" into a char.
As you go through the loop you save the characters into an array
Like kev82 said, an array is like a series of numbered boxes where you can put stuff into. So what s[i] means is find the box i in the array s and put the value of c into it. Now you might be wonder how you can put an int into an array of chars and the answer is that the int gets casted (converted) into a char (Actually, char is not a "character" variable, it's just the smallest form of an integer, usually an int is 4 bytes, while char is just a 1 byte, both store numbers, only a char can store less than an int).
Finally after the loop finishes you see:
Code:
if (c =='\n') {
s[i] = c;
++i;
Remember how the loop would end if you encounter a newliine? Well this piece of code, makes sure that the newline actually DOES get stored in the array.
Code:
s[i] = '\0';
return i;
Once the end of the function is reached (ie, a certain number of chars has been read and if a newline was encountered it was added to the array), you add the null byte ('\0') to the array. You must always add the null byte at the end, since that's how string/char array functions (strlen, strcpy, etc) determine the end of the array. Without the null byte you wouldn't be able to print the array either (unless you created a loop, but then you would also need to know how many characters to print from the array to start with). Finally in the last line you return the number of characters in the array(the number of characters that were read).