2 개의 변수가 있습니다. 하나는 unsigned short array[10]
유형이어야하며 (다른 사람에게 요청해야 함) 다른 하나는 scanf
의 입력이되어 문자열로 편리합니다.
for 루프를 사용하여 문자열에서 부호없는 short로 값을 하나씩 전달합니다.
프로그램은 정상적으로 작동하지만 경고 메시지가 표시됩니다.
"Warning passing argument of strcmp from incobatible pointer type"
및 "expected const char * but argument is of type short unsigned int"
. 경고없이 문자열에서 부호없는 short로 전달하는 방법을 찾지 못하는 것 같습니다.
내 프로그램의 짧은 버전을 사용하면 더 선명하게 볼 수 있습니다.문자열에서 부호없는 단락으로 전달
경고는 28,43 행에 있습니다.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int i, j, numberofseats;
char phone[11];
char *p;
unsigned short tempphone[10];
typedef struct
{
char fullname[40];
unsigned short phonenr[10];
unsigned int seatnr;
} PASSENGERS;
int main()
{
PASSENGERS passenger[53];
printf("Enter Passenger's Phone Nr:");
scanf("%s", phone);
i = 0;
for (p = phone; *p != '\0'; p++)
{
(tempphone[i]) = *p - '0';
i++;
}
for (j = 0; j < numberofseats; j++)
{
if (strcmp(tempphone, passenger[j].phonenr) == 0)
printf("Passenger %s has Seat Nr %u already Booked", passenger[j].fullname, passenger[j].seatnr);
}
}
'tempphone'에 실제로 사용되는 숫자의 어딘가를 저장하고 싶습니다. ** ** ** ** ** ** ** ** 처음에는 strlen (phone) 요소 만 초기화합니다. 또한,'strcmp'를 사용하여 정수의 배열을 비교할 수 없습니다. – tofro
@tofro : "* 숫자를 몇 자리에 저장 하시겠습니까 *"OP가 실제로 비교 * 작업 *을 알게 될 것입니다 ... ...--) – alk
프로그램이 잘 작동합니다. > memcmp (tempphone, passenger [j] .phonenr, sizeof (tempphone)) == 0) 두 경고가 모두 사라진 것처럼 보입니다. – baskon1