Q:

Reading/Writing with System Calls

I'm trying to write code (in C) which will read from one file, and write to a created file.  The only part I'm struggling with is the while loop, which is supposed to continuously read and write until the end of file.  I get the first 120 characters, write them, then write 'XYZ' to the file, but when I try to read/write again, I get ^@ and a bunch of garbage.  I don't want a solution on how to do this, just tell me what I am doing wrong/forgot to do. 
#include <sys/types.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

void main()
{
  int a, b, c;
  int XYZ = creat("XYZ.doc", 777);
  if(XYZ<0) {
    printf("error with creat");
    exit(0);
  }
  int xxxx = open("/usr/class/cis660/xx.xx", 0);
  if(xxxx<0) {
    printf("error with open");
    exit(0);
  }
  int tryread = 1;
  int trywrite;
  while (tryread > 0) {
    char buffer[120];
    tryread = read(xxxx, &buffer, 120);
    trywrite = write(XYZ, &buffer, 120);
    char xyz[3] = "XYZ";
    trywrite = write(XYZ, &xyz, 120);
  }
}

A:

char xyz[3] = "XYZ";
trywrite = write(XYZ, &xyz, 120);

This is your main problem.  You are trying to write 120, when you only have 3.  You have other problems:

you are not checking what read and write return
read and write don't return int, but ssize_t
open(path, 0) works, but you should use O_RDONLY
you are using void main instead of the correct int main
as Jonathan Leffler pointed out, you should use buffer instead of &buffer

A:

Your loop should only try to write as many bytes as it read:
int nread;
char buffer[120];
while ((nread = read(xxxx, buffer, sizeof(buffer)) > 0)
    int nwritten = write(XYZ, buffer, nread);
    if (nwritten ! = nread)
        ...short write error...
    char xyz[3] = "XYZ"; // Not a null terminated string
    nwritten = write(XYZ, xyz, sizeof(xyz));
    // ...check this write too
}

Note that the code does not, and should not, use &buffer and &xyz, unlike the code in the question.   The original code tried to write using data from way beyond the end of the xyz array; it also did not properly handle short writes, and would write the last buffer full a second time when it gets EOF.