Sorry, I am a newbie and this is probably easy stuff for the rest of you. I need help with my output table for my program. My output is coming out all messed up and I am at a loss on how to fix it. I know I am missing some needed code to figure out the experiment averages and the result averages, however I was trying to add one line of info at a time to make sure my input was coming out Ok (Also, nevermind the printf statements verifying input data, those are just for testing).

If anyone could help me figure out why the following happens (and how to fix it):
1). The result counter only displays "Result 1" for my output table.
2). My rest of my result headers aren't displayinging correctly.
3). The printf("--------"); statement is not displaying (separation line).
4). And why the result header line prints at the end of the each line for Experiment names.

I would be extremely grateful. Thanks

------------------------------------
***** output Table should look like:
(well all lined up nice in columns anyhow)
------------------------------------


Result 1 Result 2 Result 3 Result 4 Exp.Avg.
---------------------------------------------------------- ----------
Fred: 1.0000 2.0000 3.0000 4.0000 2.5000
Barney: 1.0000 3.0000 5.0000 7.0000 4.0000
Betty: 11.0000 13.0000 17.0000 19.0000 15.0000
----------------------------------------------------------
Result Avg: 4.3333 6.0000 8.3333 10.0000


-------------------------------------
***** But, my output looks like this:
-------------------------------------


Result 1 Exp. Avg.
Fred 1.0000 2.0000 3.0000 4.0000 Result 1 Exp. Avg.
Barney 1.0000 3.0000 5.0000 7.0000 Result 1 Exp. Avg.
Betty 11.0000 13.0000 17.0000 19.0000



Code:
#include <stdio.h>
#include <stdlib.h> 
#include <malloc.h>

struct Result {
	float value;                   /*  value of result */
	struct Result *next;
};


struct Exp {
	char ExpName[10];           
	struct Result *pt_res;
	struct Exp *next;
};

							/* Declare the list node to tie all 
							the Experiment structs together into 
							a list. */

    struct ExpList {
	struct Exp *pExp;
	struct ExpList *next;		/* --"next"-- was value */
};


/*  **************************************  */
struct Exp* GetExp(int res)

{
	static int r = 0;			/* result counter, column control */
	static int e = 0;   /*	experiment counter, row control */
/*	int res;		 input result number, columns */
/*	int exp;		 input experiment number, rows */

	struct Exp *pNewExp = NULL;
	struct Result *pTail = NULL;

	pNewExp = (struct Exp *) malloc(sizeof(struct Exp)); 
	pNewExp->pt_res = NULL;
	pNewExp->next = NULL;

		printf("\n");
		printf("Please enter the name of Experiment %d: ", ++e);
		gets(pNewExp->ExpName); 
		
		
		printf("Experiment %d name is %s:", e, pNewExp->ExpName);
		
	for (r = 0; r < res; ++r)
		{

		struct Result *pNewRes = (struct Result *) malloc(sizeof(struct Result));
		pNewRes->next = NULL;
		printf("\n");
		printf("Enter result %d for Experiment %s: ", r + 1, pNewExp->ExpName);
		scanf("%f", &pNewRes->value); 
		fflush(stdin); 

		
		printf("The result value for result %d of %s is %f:", r + 1, pNewExp->ExpName, pNewRes->value);
		
		
			/* now build the linked list - this appends to the end of the list */
			if ( pNewExp->pt_res == NULL ) {
					pNewExp->pt_res = pNewRes;
				} else {
					pTail->next = pNewRes;
				}
				pTail = pNewRes;
			}
	printf("\n");
	printf("\n");
	printf("\n");
    return pNewExp;

}

/*  **************************************  */

void PrintExp(struct Exp* pExp)

{
	int r = 0;
	int res = 0;
	int e = 0;
	int exp = 0;  


    struct Result *pList = pExp->pt_res;
	for (r = 0; r < res; ++r)

		printf("\n\t\t");
		printf("Result %d  ", ++r);
		printf("Exp. Avg.");
		printf("\n");
		
		for (r = 0; r < res; ++r)
		{
			printf("--------------");
		}    
	    printf("%s\t  ", pExp->ExpName);
		while ( pList != NULL)
			{
				printf( "%8.4f ", pList->value);
				pList = pList->next;
			}  
}

/*  **************************************  */

void PrintExpList(struct ExpList* pList)

{
		/* The first element in the list is a special case */
		PrintExp(pList->pExp);
	
		while (pList->next)    /* --"next" was value --- */
			 {
			pList = pList->next; /* --"next" was value --- */
			PrintExp(pList->pExp);
		}
}


/*  **************************************  */

void DeleteExp(struct Exp* pExp)

{
   free(pExp);
}


/*  **************************************  */

void DeleteExpList(struct ExpList* pList)

{
   struct ExpList* pCursor;

   /* we have to treat the first node in the list as a special case */
   DeleteExp(pList->pExp);

   pList = pList->next;		/* --"next" was value --- */

   while (pList)
   {
      DeleteExp(pList->pExp);
      pCursor = pList;
      pList = pList->next;		/* --"next" was value --- */

      free(pCursor);
   }
}


/*  **************************************  */

int main()
{
   
   struct ExpList list; /* handles our list for the duration of main() */
   struct ExpList* pListTail; /* Util Pointer - help us build the list */
   struct ExpList* pNewListElement; /* a utility pointer for new list nodes */
   struct Exp* pNewExp;  /* a utility pointer for new data elements */

   /* declare some variables for the control logic */
   int res = 0;
   int e; 
   int exp; 
/* int r;  */

   list.pExp = NULL;   /* Do some initialization to make our list safe (and empty) */
   list.next = NULL;	/* --"next" was value --- */

	printf("How many Experiments are there?: ");
	scanf("%d", &exp);
	fflush(stdin);

	printf("There are %d experiments:", exp);
	printf("\n");
   
	printf("How many Results are there?: ");
	scanf("%d", &res);	
    fflush(stdin);

	printf("There are %d results:", res);

  /* Now for each Experiment get a new record and add it to the list. */
  for (e = 0; e < exp; e++)       
   {
      pNewExp = GetExp(res);  /* Get a new data object from the user */

      if (list.pExp == NULL)
      {
         list.pExp = pNewExp;    /* first element in the list... */
         pListTail = &list;
      }
      else
      {		/* Make a new list node */
         pNewListElement = (struct ExpList*)malloc(sizeof(struct ExpList));
		 pListTail->next = pNewListElement;	/* hook new list node to end of list */
		 /* --"next" was value --- */	
         pListTail = pNewListElement; /* move tail marker to the new last node */
         pListTail->next = NULL;  /* new last node's next points to NULL */
		 /* --"next" was value --- */
         pListTail->pExp = pNewExp;  /* new last node points to new Experiment record */
      }
   }

   PrintExpList(&list);   /* Print list of Experiments to screen */
		printf("\n");
		printf("\n");
		printf("\n");
   DeleteExpList(&list); /* before exiting, free all the allocated memory */

   return 0;
}