본문 바로가기

C 프로그래밍

(29)
넣으면서 연결하는 이중연결 리스트 #include #include #include struct Animal{ char name[20]; double nValue; struct Animal *pre; struct Animal *next; }; struct List { int length; struct Animal* first; struct Animal* last; }; void initList(struct List*); void add(struct List*, struct Animal*); void addInIndex(struct List *, struct Animal *, int); struct Animal* makeAnimal(char*); struct Animal* getNodeAt(struct List*, int); double s..
학생을 배열리스트에 담아서 출력하고 파일로 저장하기.. #include #include #include typedef struct Student { int id; char name[40]; int age; } Student; struct ArrayList { Student *dataSet; int length; }; void initList(struct ArrayList *list){ list->dataSet = calloc(100, sizeof(Student)); list->length = 0; } void add(struct ArrayList *list, struct Student *student){ list->dataSet[list->length] = *student; list->length = list->length + 1; } void display..
파일 복사 프로그램 +_+/ 콘솔에서 돌아가요- #include void main(int args, char **argv){ FILE *source, *destination; char buffer; source = fopen(argv[1], "r+"); destination = fopen(argv[2], "w+"); buffer = fgetc(source); while(buffer != EOF){ fputc(buffer, destination); buffer = fgetc(source); } } copy a.txt b.txt 하면 스윽 옮겨서 저장해주는 프로그램 ^^ 신기해.. MSDOS 시절 생각이 납니다-
LinkedList를 활용한 도서 관리 프로그램 #include #include #include typedef struct Node { struct Book *data; struct Node *next; } node; typedef struct Book { // 제목, 저자, 출판사, 출판일, 가격 char title[30]; char author[20]; char publisher[20]; int date; int price; }; typedef struct LinkedList { int length; struct Node *fNode; }linkedList; // 1. 기본적인 링크드 리스트 함수 void initList(struct LinkedList*); node* getNodeAt(struct LinkedList*, int); void add..
C로 파일 입출력을 한번 해보았어요 -ㅅ-... #include #include #include struct Datas { char name[40]; char address[50]; char msg[60]; } ; void main(){ FILE *fp; char buffer[1024]; char *temp; int i=0; struct Datas* data = malloc(sizeof(struct Datas)); fp = fopen("Hello.txt", "r+"); fgets(buffer, 1024, fp); temp = strtok(buffer, "/"); strcpy(data->name, temp); temp = strtok(NULL, "/"); strcpy(data->address, temp); temp = strtok(NULL, "/"); ..
C로 LinkedList 구현 +_+// (아 힘들었어;; ㅋㅋ) #include #include typedef struct Node { int data; struct Node *next; } node; typedef struct LinkedList { int length; struct Node *fNode; }linkedList; node* firstNode; int length; void initList(struct LinkedList*); node* getNodeAt(struct LinkedList*, int); void add(struct LinkedList*, int); void addInIndex(struct LinkedList*, int , int); void erase(struct LinkedList*, int); void replace(struct Li..
C로 ArrayList 구현 +_+ 구조체 배운 기념으루다가 ㅋ #include #include #define INIT_LENGTH 100; struct ArrayList { int *dataSet; int length; int initLength; } list; void initList(); void initListSize(int); void add(int); void addInIndex(int , int); void erase(int); void replace(int, int); void reset(); void display(); int get(int); int isFull(); int isEmpty(); void initList() { list.initLength = INIT_LENGTH; list.dataSet = calloc(list.initLength,s..
구조체 배워보기... (안되던 부분 수정버젼) #include #include #include struct food { char name[15]; int portion_weight; int calories; }; // 얘는 작동안함. struct food init(char *setName, int setWeight, int setCalories){ struct food setMeal; strcpy(setMeal.name, setName); setMeal.portion_weight = setWeight; setMeal.calories = setCalories; return setMeal; } void main(){ struct food meals[10]; int i; for(i = 0 ; i < 10 ; i++){ meals[i] = init("헉",..