Exercise 12-8 - CBD page 425 - Lone Leth Thomsen

Solution index                   Textual C program


/* Kelly & Pohl Exercise 12.8, p. 425  */
/*                                     */
/* Lone Leth Thomsen, 11. April 2003   */

#include <string.h>
#include <stdio.h>

struct student_data {
	char *last_name;
	int student_id;
	char grade;
};

void prn_student_data(student_data std){
	printf("Name: %s, StudentId: %d, Grade: %c\n",std.last_name,std.student_id,std.grade);
};

void prn_student_data_alt(student_data std){
	printf("Name: %s,",std.last_name);
	printf("StudentId: %d,",std.student_id);
	printf("Grade: %c",std.grade);
	printf("\n");
};

struct student_data {
	char *last_name;
	int student_id;
	char grade;
};

void prn_student_data(student_data std){
	printf("Name: %s, StudentId: %d, Grade: %c\n",std.last_name,std.student_id,std.grade);
};

void prn_student_data_alt(student_data std){
	printf("Name: %s,",std.last_name);
	printf("StudentId: %d,",std.student_id);
	printf("Grade: %c",std.grade);
	printf("\n");
define the structure for student data, members last_name, student_id, grade.
 

void prn_student_data(student_data std){
	printf("Name: %s, StudentId: %d, Grade: %c\n",std.last_name,std.student_id,std.grade);
};
define a function prn_student_data taking a struct of type student as argument. The function prints each argument with an appropriate label, using the "dot" notation to select the arguments in the structure. The result is printed out in "one go".
 

void prn_student_data_alt(student_data std){
	printf("Name: %s,",std.last_name);
	printf("StudentId: %d,",std.student_id);
	printf("Grade: %c",std.grade);
	printf("\n");
give an alternative implementation of the print function where printing each component is separated.
 


Generated: Wednesday, March 29, 2006, 12:33:12
This program dissection page is generated from an XML-in-LAML source file