구조체좀 도와주세요.ㅠㅠㅠ
빗줄기
data.txt파일을 읽어서 명령문에 따라 큐에 삽입
삭제하고 매 명령 실행 직후 원형 큐 내용 전부 출력하는건데요..
삽입/삭제/오류발생
add: 큐에 삽입
delete: 큐에서 빼낸 데이터 따로 출력
fin: 큐에서 모든 데이터 빼냄(delete반복)
그외명령:오류메시지 출력
아 왜 안되는지 대체 모르겠음.ㅠㅠ
#include stdio.h
#include stdlib.h
#include string.h
#define MAX_SIZE 10
typedef struct
{
char Name[10];
char Id[10];
} STUDENT;//queue structure
void Add(STUDENT*);
STUDENT Delete(STUDENT*);
void fin(STUDENT*);
void queueEmpty(void);
void queueFull(void);
int i = 0;
int front = -1;
int rear = -1;
STUDENT queue[MAX_SIZE];//queue
char inst[MAX_SIZE];//Name save arrasa
char Name[MAX_SIZE];
char Id[MAX_SIZE];
void main(void)
{
FILE *fp;
fp = fopen(data.txt, r);
while(1)
{
fscanf(fp, %s, &inst[MAX_SIZE]);
fscanf(fp, %s, &Name[MAX_SIZE]);
fscanf(fp, %s, &Id[MAX_SIZE]);
printf(%s \n,Name[MAX_SIZE]);
if(fgetc(fp)==EOF){
puts(--------);
break;
}
else if( (strcmp(inst, add))==0 )
{
puts(---Add---);
Add(queue);//cheak
}
else if( (strcmp(inst, delete))==0 )
{
puts(---Delete---);
printf(%s, Delete(queue));//cheak
}
else if( (strcmp(inst, fin))==0 )
puts(Finish Thanks\n);
else
puts(error!!!\n);}
fclose(fp);
}
void Add(STUDENT* queue)
{
rear = (rear+1) % MAX_SIZE;
if( front == rear ){
queueFull();
}
printf(rear : %d, rear);
strncpy( queue[rear].Name, Name, strlen(Name)+1);
printf(%s\n, queue[i].Name);
strcpy( queue[rear].Id, Id, strlen(Id)+1);
printf(%s\n, queue[i].Id);
}
STUDENT Delete(STUDENT* queue)
{
if(front == rear)
queueEmpty();
front = (front+1) % MAX_SIZE;
return queue[front];
}
void fin(STUDENT* queue)
{
int i;
for(i=0; iMAX_SIZE; i++)
printf(%s , Delete(queue) );
}
void queueEmpty(void)
{
printf(Sorry, Queue is Empty);
}
void queueFull(void)
{
printf(sorry, Queue is Full);
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2692144 | C언어와 리눅스에 대한 질문입니다. | 싴흐한세여니 | 2025-04-20 |
2692114 | 컨텍스트 스위칭하는데 걸리는 시간 측정.. | YourWay | 2025-04-19 |
2692086 | 간접참조 연산자, 증감연산자 질문이용! (2) | 블랙캣 | 2025-04-19 |
2692056 | 주석좀 달아주세요. 몇개적엇는데 몇개만달아주세요. (2) | DevilsTears | 2025-04-19 |
2691978 | 진수 쉽게 이해하는법... (3) | 지지않는 | 2025-04-18 |
2691949 | getchar() 한 문자를 입력받는 함수 질문 | 채꽃 | 2025-04-18 |
2691919 | 배열 정렬 및 합치기 질문입니다. | 사과 | 2025-04-18 |
2691845 | c언어왕초보 질문이 있습니다........ | 루나 | 2025-04-17 |
2691815 | void add(int num); 함수... (4) | 살랑살랑 | 2025-04-17 |
2691756 | 명령 프롬프트 스크롤바가 없어요 | 두메꽃 | 2025-04-16 |
2691725 | 자료구조에 관련해서 질문이 있어 글을 올립니다. | 누리알찬 | 2025-04-16 |
2691697 | if 문에서 구조체 배열에 저장되있던 문자열 검사하는 법 ? (2) | 민트맛사탕 | 2025-04-16 |
2691678 | C언어 함수 질문이요~!!! | 연보라 | 2025-04-15 |
2691650 | 반복문 | 돋가이 | 2025-04-15 |
2691618 | 링크드리스트 개념 질문이예요 (3) | 맨마루 | 2025-04-15 |
2691592 | 동적할당 이용 배열선언 질문입니다.ㅠㅠ (3) | 허리달 | 2025-04-15 |
2691542 | /=의 용도를 알려주세요 ㅠㅠ! (2) | 아라 | 2025-04-14 |
2691510 | sizeof 연산자 질문입니다 (2) | 종달 | 2025-04-14 |
2691483 | 파일 오픈시 에러 질문드립니다. (2) | 호습다 | 2025-04-14 |
2691450 | [visual c++ 툴]기초 질문 (3) | 해긴 | 2025-04-13 |