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];

int main()
   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);

   return 0;

void menu()

	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


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()

This article has been dead for over six months. Start a new discussion instead.