putting strings together through structures & functions
I can get the names entered in this code but the output is strange characters.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NUM_EMPL 5
struct employee
{
char name[20]; /*name*/
};
void get_input (struct employee emp[])
{
/*Local Variable Declaration */
char first_name[20], last_name[20];
int count; /* Variable used in loop counter */
for (count = 0; count < NUM_EMPL; ++count)
{
printf("Enter First Name ");
scanf ("%s", first_name);
printf("Enter Last Name ");
scanf ("%s", last_name);
}
strcpy(emp[count].name, first_name);
strcat(emp[count].name, " ");
strcat(emp[count].name, last_name);
printf("\n\n\n");
}
void output_screen (struct employee emp[])
{
/*Local Variable Declaration */
int count; /* Variable used in loop counter */
/*print output in table format using arrays */
for (count = 0; count < NUM_EMPL; ++count)
{
printf ("Employee name is %s\n", emp[count].name);
}
}
main()
{
struct employee emp[NUM_EMPL];
get_input(emp);
output_screen(emp);
system("PAUSE");
return 0;
}
my output is similar to this.. not exactly this (didnt know how to capture my output
:confused:
Code:
Employee name is
Employee name is xë
Employee name is ª Ø
Employee name is Þ ë
Employee name is