Problem:
μ
λ ₯ λ°μ΄ν° :
[Command.txt
0.00MB](https://blog.kakaocdn.net/dna/bnbU30/btqBgeimBnY/AAAAAAAAAAAAAAAAAAAAAAPakDbTA4jf0WyG_DmDE76emfyLiazho4x1advtOToN/Command.txt?credential=yqXZFxpELC7KVnFOS48ylbz2pIh7yKj8&expires=1788188399&allow_ip=&allow_referer=&signature=2iAm290NW4CFkRgpHKAQHRqBvxw%3D&attach=1&knm=tfile.txt) Execution Result:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 #include<stdio.h> #include<string.h> #include<stdlib.h> void PrintAssm(char* name_buf, int name_size); struct OPTAB{ char name[8]; int len; } Wordtab[] = { {"LDA", 3}, {"STA", 4}, {"ADD", 5}, {"TIX", 2}, {"CMP", 6} }; int main() { char name_buf[8]; int wordtab_size = sizeof(Wordtab)/12; // Wordtabμ μ μλ λ¨μ΄ κ°―μ, 12 = size of char[8] + int FILE* fp; if((fp = fopen("Command.txt", "r"))==NULL) { printf("file not found...\n"); exit(1); } while(fgets(name_buf, sizeof(name_buf), fp) != NULL) { // fgets() ν¨μλ scanfλ gets()μλ λ¬λ¦¬ λ€μ κ°νλ¬Έμκ° λΆλλ€ if(name_buf[0] == '\n') // name_buf λ°°μ΄ λ§¨ μ²μμ΄ κ°νλ¬Έμμ΄λ©΄ λ©μμ§ μΆλ ₯ μμ΄ λ¬΄μ continue; if(name_buf[strlen(name_buf) - 1] == '\n') // name_buf λ°°μ΄ λ§¨ λμ΄ κ°νλ¬Έμμ΄λ©΄ name_buf[strlen(name_buf) - 1] = '\0'; // naem_buf λ°°μ΄ λ§¨ λμ λΆμ κ°νλ¬Έμ μ κ±° PrintAssm(name_buf, wordtab_size); } fclose(fp); } void PrintAssm(char* name_buf, int wordtab_size){ static int k=1; // μ€ λ²νΈλ₯Ό λνλ΄λ λ³μ static int loc=0; // λ¨μ΄μ μμ μμΉλ₯Ό λνλ΄λ λ³μ int i, res=-1; for(i=0; i<wordtab_size; i++){ res = strcmp(name_buf, Wordtab[i].name); // strcmp : λ λ¬Έμμ΄μ΄ κ°μΌλ©΄ 0 λ¦¬ν΄ if(res==0){ break; } } if(i==wordtab_size){ printf(" Undefined word\n"); // Wordtab λ°°μ΄ μμ μ μλμ΄ μμ§ μλ λͺ
λ Ήμ΄λ©΄ μΆλ ₯νκ³ λ¨μ΄ 무μ } else{ if(k < 10) printf(" "); printf("%d, %.2X, %s, %.2d\n", k, loc, Wordtab[i].name, Wordtab[i].len); loc += Wordtab[i].len; // λ¨μ΄μ ν΄λΉκΈΈμ΄λ₯Ό λν΄μ λ€μ μμ μμΉλ₯Ό μλ €μ€ k++; } } Explanation:
...