hello everyone umm I'm having trouble in printing a structure in c... is a program to calculate benefits of employees in a company when they are fired.. getting trouble when printing the hired date of an employee here its the code

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

void menu();

struct employee{
	char company[70];
	char name[50];
   char hired_date[10];
   char fired_date[10];
   double salary[5];
}empl;

int main()
{
	menu();
   gotoxy(31,4); gets(empl.company);              
   gotoxy(31,5); gets(empl.name);                 
   gotoxy(31,6); scanf("%s", empl.hired_date);
   gotoxy(66,6); scanf("%s", empl.fired_date);


   gotoxy(20,19);printf("%s", empl.company);
   gotoxy(20,20);printf("%s", empl.name);
   gotoxy(20,21);printf("%s", empl.hired_date);  //PROBLEM HERE!!
   gotoxy(20,22);printf("%s", empl.fired_date);



	getch();
   gotoxy(45,24);system("pause");
   return 0;

void menu()
{

	cuadrado(75,6,2,2);
	gotoxy(5,4); printf("Company Name.......:");
   gotoxy(5,5); printf("Employee Name...........:");
   gotoxy(5,6); printf("Hired Date..............:");   gotoxy(42,6); printf("Fired Date..........:");

}

.. HELP!! why when I printf the hired date it print both? hired and fired date?? like this

01/01/2011/01/01/2012

Because the dates are stored as character arrays, not strings. A string ends in with '\0'. You have space for the date only: 01/01/2012 = 10 characters.

Define your dates as 11 or more characters make sure you load a '\0' in the 11th position.

Also, see this about using gets() and scanf()

I would also use printf format string properly (for example "%30s") instead of gotoxy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.