void Students_Absence_Report()
{
	int i;
	double presence[NO_OF_STUDS], absence[NO_OF_STUDS];

	for(i=0; i<NO_OF_STUDS; i++)
	{
		presence[i] = ((double)student[i].presentDays/14)*100;
		absence[i] = 100 - presence[i];
	}

	printf("\n\nStudents Presence/Absence Report\n");
	printf("--------------------------------\n");
	printf("    Name\t\t%%Presence\t%%Absence\n");	

	for(i=0; i<NO_OF_STUDS; i++)
	{
		printf("%-3d %-19s %.2f\t\t%.2f\n", student[i].studNo, strcat(student[i].surname, student[i].givenName), presence[i], absence[i]);
		
	}
	printf("\n******** END OF ATTENDANCE REPORT ********\n");
}

Anythings wrong in this function? everytime i do loopinh, the strcat will generate larger and larger name...anywhr to solve tis??

Edited 6 Years Ago by cedric91: n/a

Please take a look at strcat.

First parameter of strcat is the destination string, second one is the source string that will be appended to destination string.

e.g.
Consider the code piece below:

dest = "Destination,"
src = "Source,"
call strcat (dest, src)  // this method call will assign new value to dest variable.

After above call dest variable will contain "Destination,Source,"

If this is done over and over again, dest variable will be appended with src text.

To avoid this case you should do something like this:

char tempString[100];  // this should be done outside loop.
                       // Array length should be large enough to hold both surname
                       // and firstname.

//in for look do the following
strcpy(tempString, student[i].surname);
strcat(tempString, student[i].givenName);
printf("%-3d %-19s %.2f\t\t%.2f\n", student[i].studNo, tempString, presence[i], absence[i]);

Note: I have written the code from memory, I haven't tested it. Please bear with it :D

This question has already been answered. Start a new discussion instead.