コード例 #1
0
int main() {
    printf("Starting program stest.\n");
    #ifdef DEBUG
    printf("DEBUG defined\n");
    #else
    printf("Not defined\n");
    #endif
    //--------------------Creating and Printing Employee--------------------------
    Employee* tri;
    Employee* jetro;
    tri = createEmployee(20000, "Tri", "Robotics");
    jetro = createEmployee(20000,"Jetro", "Electrical");
    // Anybody recognize these names?
    Employee harry; // Declare a local variable (a struct).
    harry.salary = 5000;
    harry.name = strdup("Harry Palmer"); // Make a dynamic copy.
    harry.dept = strdup("Mechanical");
    
    Employee bluejay; // Declare a local variable (a struct).
    bluejay.salary = 10000;
    bluejay.name = strdup("Erik Grantby"); // Make a dynamic copy.
    bluejay.dept = strdup("Computer Science");

    // Output the employees to stdout.
    printEmployee(&harry);
    printEmployee(&bluejay);
    printEmployee(tri);
    printEmployee(jetro);
    //---------------------Ending Employee---------------------
  
  
  	//---------------------Getting Employee's Info From Prompts------------------------- 
	
  	getEmployeeInfo(100, 100, 100);
  	
  	
  	//---------------------End Prompts------------------------- 
	//Output the employees to a file.
  	printf("About to write to file.\n");
  	FILE *outfile;
  	outfile = fopen("stest.txt", "w"); // Open or create file for writing
  	if(outfile != '\0'){// check if outfile can be opened
    	printf("outfile opened sucessfull\n");// prompt succes
    	// write the data to outfile
    	outputEmployee(outfile, &harry);
    	outputEmployee(outfile, &bluejay);
    	outputEmployee(outfile, tri);
    	outputEmployee(outfile, jetro);
    	fclose(outfile);// close outfile
 	}
  	else{
    	fprintf(stderr, "Uh-oh!\n");//print error if file can't be opened
  	}
 

  	printf("Ending program stest.\n"); 
  	return 0;
}
コード例 #2
0
ファイル: stest.c プロジェクト: tusharnarayan/wpi-cs
/** 
 * main function
 * @return 0 indicating success, 1 indicating file not opened successfully
 */
int main() {
  printf("\nStarting program stest.\n\n"); 

  // Anybody recognize these names?
  Employee harry; // Declare a local variable (a struct).
  harry.salary = 5000;
  harry.name = strdup("Harry Palmer"); // Make a dynamic copy.
  harry.dept = strdup("MI6"); // Make a dynamic copy.
  
  Employee bluejay; // Declare a local variable (a struct).
  bluejay.salary = 10000;
  bluejay.name = strdup("Erik Grantby"); // Make a dynamic copy.
  bluejay.dept = strdup("KGB"); // Make a dynamic copy.

  //Creating employees dynamically using function makeEmployee
  Employee* jason = makeEmployee(10000, "Jason Bourne", "CIA");
  int temp_salary = 1000;
  char *temp_name = "Carlos the Jackal";
  char *temp_dept = "Novgorod";
  Employee* carlos = makeEmployee(temp_salary, temp_name, temp_dept);
  Employee* user_emp1 = inputEmployee();
  
  // Output the employees to stdout.
  printEmployee(&harry);
  printEmployee(&bluejay);
  printEmployee(jason);
  printEmployee(carlos);
  printEmployee(user_emp1);
  
  // Output the employees to a file.
  printf("\nAbout to write to file.\n");
  FILE *outfile = fopen("stest.txt", "w"); // Open or create file for writing
  if(outfile == NULL){
    fprintf(stderr, "Whoops! stest had error number %d - %s\n", 
	    errno, strerror(errno));
    return 1;
  }
  outputEmployee(outfile, &harry);
  outputEmployee(outfile, &bluejay);
  outputEmployee(outfile, jason);
  outputEmployee(outfile, carlos);
  outputEmployee(outfile, user_emp1);
  fclose(outfile); // Close the file

  printf("\nEnding program stest.\n"); 
  debug_def_checker();
  return 0;
}
コード例 #3
0
ファイル: employeef.c プロジェクト: Spkordell/cs2303
/** Outputs all the Employee structures defined in an array of pointers of structures to the specified file stream
 * @param stream The open stream to output to
 * @param employeePtrArray The array of pointers to structs to dereference and print
 * @param count Number of elements in the array
 *@author Steven Kordell
 */
void outputEmployeeArray(FILE* stream, Employee** employeePtrArray, int count) {
  int i; //An iterator for looping through the array
  for(i = 0; i < count; i++) {                  //iterater over the array
    outputEmployee(stream,employeePtrArray[i]); //write the struct to the file
  }
}