내 프로그램에 대한 테스트를하고 있었고 프로그램이 내 기능을 입력 할 때 왜 충돌하는지 궁금해하고있었습니다. 프로그램의 논리에 신경 쓰지 마라. 내가 지금 내 도구를 사용하는 방법을 이해하는 단계에 있었기 때문이다.문자 배열과 포인터에 관한 구문이 무엇이 있습니까?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Constants */
#define HEX_CAPITAL_LETTERS_BEGIN 65
#define HEX_CAPITAL_LETTERS_END 90
#define HEX_NUMBERS_BEGIN 48
#define HEX_NUMBERS_END 57
#define EXIT_SUCCES 0
/* Prototypes */
void codeToField(char *charArray, int i, int hexFloor, int hexCeil, char *outputArray);
/* Main Function */
int main(void) {
char *code, warehouse, product, qualifiers;
int i = 0;
printf("Enter a MMOC product code: ");
scanf("%s", &code);
codeToField(code, i, HEX_CAPITAL_LETTERS_BEGIN, HEX_CAPITAL_LETTERS_END, &warehouse);
codeToField(code, i , HEX_NUMBERS_BEGIN, HEX_NUMBERS_END, &product);
strcpy(&qualifiers, code + i);
printf("\n\nWarehouse: %s\nProduct: %s\nQualifiers: %s\n", &warehouse, &product, &qualifiers);
return EXIT_SUCCES;
}
void codeToField(char *charArray, int i, int hexFloor, int hexCeil, char *outputArray) {
int j = 0;
while (charArray[i] >= hexFloor && charArray[i] <= hexCeil) {
outputArray[j] = charArray[i];
i++;
j++;
}
}
미리 감사드립니다.
왜 'A', 'Z', '0'등 대신 '65'와 '90'같은 숫자를 사용합니까? – trentcl
왜 'strcpy'를 하나의 문자로 만들려고합니까? –
@ M.M 내가 말했듯이 손에있는 문제 이외에 아무 것도 신경 쓰지 마라. 아직도 내가 원하는 걸 찾아 내려고 노력하고 있었고, 실제로 테스트 해봤습니다. 문제를 제기 한 모든 것은 하하를 게시하기 전에 주석 처리되었습니다. –