我不能得到我的預期結果我希望我的程序顯示任何人都可以幫助我。該程序將打印結構中列出的工人名稱,如果您未輸入任何這些名稱,則應打印工人名稱不存在。誰能告訴我的代碼/語法使用如果聲明打印工人名稱
這裏是我有什麼
#include <stdio.h>
#include <conio.h>
#include <string.h>
//Program Purpose: To accept a specific set of worker names and worker id number and accept the time they came to work and determine if they were early or late for the day.`
struct workers {
char worker_name[10];
int worker_id;
} workers;
int main()
{
struct workers worker1;
struct workers worker2;
strcpy (worker1.worker_name, "sean");
worker1.worker_Id = 1234;
strcpy (worker2.worker_name,"tajae");
worker2.worker_Id = 7890;
char worker_name [30];
int Worker_Id;
float Time_Arrived;
float Minutes_Late;
float Extra_Minutes;
float Minutes_Early;
float lunch_time;
float Departure;
printf("******************Produce Pro Time Management System********************\n\n");
printf("Good morning. Welcome to Produce Pro, Hope you had a good nights rest and ready to have a successful day at work today.\n\n");
printf("Please follow the instruction and answer with the required details\n");
printf("Note brief: All time are in army hours\n\n");
printf("Enter your Worker Name\n");
scanf("%S",&worker_name[30]);
if (worker_name= worker1,worker2) // this is the error in the program//
{
printf(&worker_name[30]);
}
else
{
printf ("Worker Name doesn't exist");
}
}
當我做出改變if語句,把
if (worker_name == worker1.worker_name || worker_name == worker2.worker_name)
{
printf("Welcome %s\n",worker_name);
}
else printf ("Worker Name doesn't exist\n");
工人不eixt是什麼我得到
您需要使用字符串比較功能,比如'strcmp'或更安全'strncmp'爲10的極限,因爲這是你的字符串的最大長度。 – pstrjds 2015-04-01 18:56:44
縮進4個空格(或選擇您的代碼並按下Ctrl-K)來格式化它。不要使用反引號代碼塊。 – chi 2015-04-01 18:56:45
等待,它不只是'strcmp()'你爲什麼要這樣'Worker_name = worker1,worker2'? – 2015-04-01 18:57:24