|
글쎄요 왜 바꿀려고 하지요 그냥 사용하시지요!
이것도 못 바꾸는 실력이면 여기서 해결 해줘도 역시 다른곳에서 걸릴겁니다.
구조체를 보니 문자열을 입력받기 위해서 char배열을 사용한것 같습니다. 따라서 님과 같이 int형을 멤버로 사용 할려면 거의 대부분의 고쳐야합니다. 문법적으로 처리 방식이 다르다는 애깁니다.
int로 바꾸게 되면
strcpy(mt[i].month, ""); ==> mt[i].month = 0
gets(t.month); == > gets(temp);사용한 후 atoi(....)류의 함수로 숫자로 바꿔야 합니다.
strcmp(s, "Y") == 0 ==> s = 'Y' 씩으로 바꿔야 합니다.
..........................
논리적으로도 많은 부분이 수정 되어야합니다.
문법책을 한번이라도 읽어 보시거나 원작자에게 새로 요청하는게 빠를듯합니다.
그럼
오정이 님이 쓰신 글 :
: 저기요 제발 도와주세요....
: typedef struct {
: char month[20] 를
: int month[20]으로 바꿔서 할려고 합니다
: int month[20]으로 바꿔서 하면 오류가 상당히 많이 나옵니다.
: 오류가 안나오게 하려면 어떻게 해야 하나요... 알려주세요...ㅜ.ㅠ
:
:
: #include <stdio.h>
: #include <string.h>
:
: #define MAX_MEM 200
: #define TRUE 1
: #define FALSE 0
: #define ERR -1
:
: typedef struct {
: char month[20];
: char stone[20];
: char star[20];
: char valid; // 유효유무 : 'Y' 유효, 'N' 무효
: } MEMBER;
:
: MEMBER mt[MAX_MEM];
:
: int Menu();
: void Insert();
: int Search_Blank();
: void Write(int i, MEMBER a);
: int Search_Month(char s[]);
: void Search();
: void Delete();
: void Update();
:
: void main() {
: int sel, i;
:
: // 초기화 : 이름 = ""
: for (i = 0; i < MAX_MEM; ++i)
: strcpy(mt[i].month, "");
: // mt[i].name[0] = '\0';
:
: while (1) {
: sel = Menu();
: switch (sel) {
: case -1:
: printf("[Error] Not number\n");
: break;
: case 1:
: Insert();
: break;
: case 2:
: Update();
: break;
: case 3:
: Delete();
: break;
: case 4:
: Search();
: break;
: case 0:
: return;
: default:
: printf("[Error] Out of range\n");
: }
: }
: }
:
: int Menu() {
: char s[81];
: int sel;
:
: printf("=============================================\n");
: printf(" [0]종료 [1]입력 [2]수정 [3]삭제 [4]검색(월) \n");
: printf("=============================================\n");
: printf(" Choice number = ");
: gets(s);
: if (sscanf(s, "%d", &sel) != 1)
: return -1;
: else
: return sel;
: }
:
: void Insert() {
: MEMBER t;
: int i;
: char s[81];
:
: printf("<<< Insert program >>>\n");
: while (TRUE) {
: printf("Month : ");
: gets(t.month);
: if (strlen(t.month) == 0)
: break;
: if (Search_Month(t.month) != ERR) {
: printf("[Msg] Already exist\n");
: continue;
: }
: printf("Stone : ");
: gets(t.stone);
: printf("Star : ");
: gets(t.star);
: i = Search_Blank();
: if (i == ERR) {
: printf("[Error] Memory Full\n");
: break;
: }
: printf("Really? (Y/N) ");
: gets(s);
: if (strcmp(s, "Y") == 0) {
: Write(i, t);
: printf("[Msg] Inserted in location %d\n", i);
: }
: }
: }
:
: int Search_Blank() {
: int i;
: for (i = 0; i < MAX_MEM; ++i) {
: if (strlen(mt[i].month) == 0)
: return i;
: if (mt[i].valid == 'N')
: return i;
: }
: return ERR;
: }
:
: void Write(int i, MEMBER a) {
: strcpy(mt[i].month, a.month);
: strcpy(mt[i].stone, a.stone);
: strcpy(mt[i].star, a.star);
: mt[i].valid ='Y';
: }
:
: int Search_Month(char s[]) {
: int i;
: for (i = 0; i < MAX_MEM; ++i)
: if ((strcmp(mt[i].month, s) == 0) &&
: (mt[i].valid == 'Y'))
: return i;
: return ERR;
: }
:
: void Search() {
: char s[20];
: int i;
:
: printf("<<< Search with month >>>\n");
: while (TRUE) {
: printf("Month for search : ");
: gets(s);
: if (strlen(s) == 0)
: break;
: i = Search_Month(s);
: if (i == ERR)
: printf("[Msg] Can't find\n");
: else {
: printf("Stone : %s\n", mt[i].stone);
: printf("Star : %s\n", mt[i].star);
: }
: }
: }
:
: void Delete() {
: char s[20];
: int i;
:
: printf("<<< Delete with month >>>\n");
: while (TRUE) {
: printf("Month for delete : ");
: gets(s);
: if (strlen(s) == 0)
: break;
: i = Search_Month(s);
: if (i == ERR)
: printf("[Msg] Can't find\n");
: else {
: printf("Really? (Y/N) ");
: gets(s);
: if (strcmp(s, "Y") == 0) {
: mt[i].valid = 'N';
: printf("[Msg] Deleted in location %d\n", i);
: }
: }
: }
:
: }
:
: void Update() {
: MEMBER t;
: char s[20];
: int i;
:
: printf("<<< Update with month >>>\n");
: while (TRUE) {
: printf("Month for update : ");
: gets(t.month);
: if (strlen(t.month) == 0)
: break;
: i = Search_Month(t.month);
: if (i == ERR)
: printf("[Msg] Can't find\n");
: else {
: printf("Stone (%s) : ", mt[i].stone);
: gets(t.stone);
: printf("Star (%s) : ", mt[i].star);
: gets(t.star);
: printf("Really? (Y/N) ");
: gets(s);
: if (strcmp(s, "Y") == 0) {
: Write(i, t);
: printf("[Msg] Updated in location %d\n", i);
: }
: }
: }
: }
|