구조체에 저장된 요소를 역순으로 출력하려면 어떻게 해야하나요?
조히
질문 제목 : 구조체에 저장된 요소를 역순으로 출력하려면 어떻게 해야하나요? 질문 내용 :
렉스랑 심볼테이블 만들고 있는데요
심볼테이블에 저장이 된 원소를 저장된 순서대로 출력을 하고싶은데 오히려 역순으로 출력이 되요
예를 들면
저장이 1, 2, 3, 4, 5 순으로 되었다면
출력은 5, 4, 3, 2, 1 이렇게 역으로 출력이 되네요..//symbol table
struct symtab
{
char *id; // id
int lines; // where it is used
struct symtab *next; // pointer to symbol
};
struct symtab *first; // first element, first declared symbols
struct symtab *sym_list; //first element, declared symbols
struct symtab *unde; // first element, undeclared symbols
extern void *malloc();
// store the first declared symbol
addfirst(char *word, int where)
{
struct symtab *sym;
sym =(struct symtab*) malloc(sizeof(struct symtab));
sym-next = first;
sym-id=(char*) malloc(strlen(word)+1);
strcpy(sym-id, word);
sym-lines=where;
first=sym;
}
// store declared symbol if it is used
add(char *word, int where)
{
struct symtab *sym;
sym =(struct symtab*) malloc(sizeof(struct symtab));
sym-next = sym_list;
sym-id=(char*) malloc(strlen(word)+1);
strcpy(sym-id, word);
sym-lines=where;
sym_list=sym;
}
// store undefined symbol
addundec(char *word, int where)
{
struct symtab * unsym;
unsym =(struct symtab*) malloc(sizeof(struct symtab));
unsym-next = unde;
unsym-id=(char*) malloc(strlen(word)+1);
strcpy(unsym-id, word);
unsym-lines=where;
unde=unsym;
}
//look for declared symbol
int lookup2(char * word)
{
struct symtab *fp = first;
for( ; fp;fp=fp-next){
if(strcmp(fp-id, word)==0)
{
return fp-lines; //declared, return the declared line
}
}
return undeclared; //not found;
}
// look for lines where declared symbol is used
int lookup(char *word)
{
struct symtab *wp=sym_list;
for( ; wp;wp=wp-next){
if(strcmp(wp-id, word)==0)
{
return wp-lines; //declared, return the declared line
}
}
return undeclared; //not found;
}
//여기부터 출력이 문제..
// print out declared symbols
printdeclared()
{
printf(symbols:\n);
char *tok;
struct symtab *fp = first;
struct symtab *ptr = sym_list;
while(fp!=null)
{
tok = fp-id;
printf(%s - declared on %d, used on , tok, lookup2(tok));
for( ; ptr!=null ; ptr = ptr-next)
{
if(strcmp(ptr-id, tok)==0)
{
printf(%d, , ptr-lines); //저장된 순서의 역순으로 출력이 되요 여기가;
}
}
ptr=sym_list;
fp=fp-next;
printf(\n);
}
// next, printout undeout undeclared symbols
printundeclared();
}제가 원하는 출력하려면 어떻게 고쳐야하나요?
-
꺆잉
사사삭 봤는데
printdeclared() -이함수에서
{
printf(\Symbols:\\n\); --------- 선언보다 먼저 왔네요
char *tok;
struct symtab *fp = first;
struct symtab *ptr = sym_list;
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2694854 | 절대값을 구할때 (2) | 그녀는귀여웠다 | 2025-05-15 |
2694827 | 이제 어떻게 공부해야할지 모르겠네요 | 새얀 | 2025-05-14 |
2694778 | 순열 계산요. | 맛조이 | 2025-05-14 |
2694754 | ShowWindow 함수를 이용하려 하는데 질문있습니다. (2) | 파도 | 2025-05-14 |
2694731 | 리눅스 커널의 시작점 질문 | 미르 | 2025-05-13 |
2694702 | 이거 뭐가문제인가요 코드수정좀 (3) | 맑은 | 2025-05-13 |
2694675 | C언어 후위표기를 중위표기로 | 앨런 | 2025-05-13 |
2694646 | 안녕하세요 파일 합치기 함수! (1) | 연블루 | 2025-05-13 |
2694618 | 잘몰라서 설명부탁드립니다. scanf 관련 (3) | 파라 | 2025-05-12 |
2694590 | 이 코드가 뭐하는 코드일까요? #2 | 빵순 | 2025-05-12 |
2694559 | 동적할당으로 배열(2차원열)을 만드는데 있어 그걸 함수화시키는데... (1) | 늘솔길 | 2025-05-12 |
2694532 | 네트워크에 관하여... (4) | 황소자리 | 2025-05-12 |
2694503 | 프로그램 연산 후 바로 종료되는 현상 (6) | Judicious | 2025-05-11 |
2694450 | while문질문입니다. (1) | 허리품 | 2025-05-11 |
2694420 | C언어 질문할게요(유니코드,자료형,버퍼,캐스트연산자) | 은새 | 2025-05-11 |
2694370 | 내일까진데 함수호출 제발 도와주세요!!!!!!!!!11 | 들찬 | 2025-05-10 |
2694339 | putchar()의 괄호 안에 int c=10;로 전에 선언된 c를 넣으면 안되는 이유에서 제가 생각한 것이 그 이유가 되는지 확인하고 싶습니다. (3) | 미르 | 2025-05-10 |
2694316 | 이 코드 어디가 잘못되었는지 고수분들 ㅠㅠ (2) | 나빛 | 2025-05-10 |
2694285 | 언어 공부하는 과정 좀 추천해주세요! (1) | 아빠몬 | 2025-05-09 |
2694258 | 카운터.. 질문입니다. (4) | 하늘빛눈망울 | 2025-05-09 |