If you are aware of the
write()
function you should be also aware of the
read()
function. To read from the keyboard pass zero as first parameter (file descriptor
stdin).
Use a
while
loop to read single characters and store them in an array until a new line (
'\n'
) occurs (user pressed the ENTER key). Store the number of characters read in a variable and/or terminate the string with a NULL byte.
Compare the two arrays. The first check is comparing the lengths which has been stored in variables after reading the user input. If they do not match, the comparison has failed. Otherwise iterate over the arrays using a
for
loop comparing each character until there is a mismatch (comparison failed) or the loop finishs (comparision succeeded).
Finaly use
open()
to create the file to write the output.
If you need a description for the system functions, you can use the Linux man pages like
read(2) - Linux manual page[
^]. They can be simply found by searching the web for "man 2 <function_name>". The "2" is the man page section for system calls. All functions from this section should be useable with
ShellForge.