Diễn Đàn Thảo Luận Máy Tính
Đăng ký để tận hưởng nào Khách viếng thăm !!!!!!!!!!

Join the forum, it's quick and easy

Diễn Đàn Thảo Luận Máy Tính
Đăng ký để tận hưởng nào Khách viếng thăm !!!!!!!!!!
Diễn Đàn Thảo Luận Máy Tính
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
Tìm kiếm
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Quân Đội Nhân Dân Việt Nam
Bai tap lab 10 Icon_minitimeSun Feb 16, 2014 3:23 pm by Admin

» Tải game APO Snow cho android
Bai tap lab 10 Icon_minitimeTue Dec 17, 2013 10:17 am by ducls1102

» Bài hát cho những người lính
Bai tap lab 10 Icon_minitimeTue Aug 13, 2013 11:20 am by Admin

» Nhạc hay của tui :(
Bai tap lab 10 Icon_minitimeFri May 04, 2012 10:44 pm by Admin

» Tìm lại giây phút yên bình của ngày hôm qua
Bai tap lab 10 Icon_minitimeMon Apr 09, 2012 1:09 am by Admin

» PHIÊN BẢN MỚI CHO THIÊN ĐƯỜNG CÁ Ô LA LA !!!
Bai tap lab 10 Icon_minitimeWed Mar 07, 2012 3:40 pm by nikitait

» Đáp án Assignment từ đề 1 đến đề 3
Bai tap lab 10 Icon_minitimeTue Sep 13, 2011 1:13 pm by viennv170993

» Aloooooooooooooooooooooooooooooooooooo
Bai tap lab 10 Icon_minitimeSat Jun 04, 2011 2:21 pm by shanshiaro

» Tro Lai Cua 1 Mod
Bai tap lab 10 Icon_minitimeSat Jun 04, 2011 2:21 pm by shanshiaro

Affiliates
free forum

RSS feeds


Yahoo! 
MSN 
AOL 
Netvibes 
Bloglines 



Bai tap lab 10

3 posters

Go down

Bai tap lab 10 Empty Bai tap lab 10

Bài gửi by dathl_c00493 Sat Jan 08, 2011 5:46 pm

struct & file
dathl_c00493
dathl_c00493
Mod
Mod

Tổng số bài gửi : 28
Ngày tham gia : 10/12/2010
Tuổi : 33
Đến từ Đến từ : THAI BINH

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Người chơi

Về Đầu Trang Go down

Bai tap lab 10 Empty bai 1

Bài gửi by dathl_c00493 Sat Jan 08, 2011 5:48 pm

Code:

/*
tao file myfile.txt,
nhap noi dung tu ban phim, ky tu, chuoi roi luu vao file
mo file doc cac ndung da co
*/
#include<stdio.h>
int writeFile(char *fileName, char *str);
//doc het cac ndung trong file (count)
int readFile(char *fileName, char *str);
int main(){
    char str[81];
   
    readFile("myfile.txt", str);
    printf("\nnhap vao chuoi: ");
    fflush(stdin);
    gets(str);
    strcat(str, " ");
    writeFile("myfile.txt", str);
    fflush(stdin);
    getchar();
}
int writeFile(char *fileName, char *str){
    FILE *f;
    f = fopen(fileName,"a");
    if(f == NULL)
        return 0;
    fputs(str, f);
    fclose(f);
}
int readFile(char *fileName, char *str){
    FILE *f;
    //char *str;
    f = fopen(fileName, "r");
    if(f == NULL)
        return 0;
    while(!feof(f)){
    fgets(str, 81, f);
    printf("%s", str);
    }
    fclose(f);
}

dathl_c00493
dathl_c00493
Mod
Mod

Tổng số bài gửi : 28
Ngày tham gia : 10/12/2010
Tuổi : 33
Đến từ Đến từ : THAI BINH

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Người chơi

Về Đầu Trang Go down

Bai tap lab 10 Empty bai 2

Bài gửi by dathl_c00493 Sat Jan 08, 2011 5:49 pm

Code:

#include<stdio.h>

typedef struct{
        char name[50];
        short age;
        char address[100];
}infoPerson;
infoPerson inputInfo();
int writeFile(char *fileName, infoPerson Person);
int readFile(char *fileName, infoPerson *Person);
void displayPerson(infoPerson Person);
int main(){
    infoPerson Person;
    char fileName[10] = "myfile.dat";
    readFile(fileName, &Person);
    displayPerson(Person);
    Person = inputInfo();
    writeFile(fileName, Person);
    fflush(stdin);
    getchar();
}

infoPerson inputInfo(){
          infoPerson Person;
          printf("Ten: ");
          fflush(stdin);
          gets(Person.name);
          printf("Tuoi: ");
          scanf("%d", &Person.age);
          printf("Dia chi: ");
          fflush(stdin);
          gets(Person.address);
          return Person;
}
int writeFile(char *fileName, infoPerson Person){
    FILE *f;
    f = fopen(fileName,"wb");
    if(f == NULL)
        return 0;
    fwrite(&Person, sizeof(infoPerson), 1, f);
    fclose;
}
int readFile(char *fileName, infoPerson *Person){
    FILE *f;
    f = fopen(fileName, "rb");
    if(f == NULL)
        return 0;
    fread(Person, sizeof(infoPerson), 1, f);
    fclose(f);
    return 1;
}
void displayPerson(infoPerson Person){
    printf("Ten: ");
    printf("%s\n", Person.name);
    printf("Tuoi: ");
    printf("%d\n", Person.age);
    printf("Dia chi: ");
    printf("%s\n\n", Person.address);
   
}

dathl_c00493
dathl_c00493
Mod
Mod

Tổng số bài gửi : 28
Ngày tham gia : 10/12/2010
Tuổi : 33
Đến từ Đến từ : THAI BINH

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Người chơi

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by dathl_c00493 Sat Jan 08, 2011 5:51 pm

Code:

#include<stdio.h>
#include<string.h>
int menu();
struct dict{
        char word[30];
        char description[50];
        char type;
};
struct dict inputVocab();
int writeFile(char *fileName, int count, struct dict *vocab);
int readFile(char *fileName, struct dict *vocab);
void showHeader();
void showLine();
void displayVocab(struct dict *vocab, int count);
int searchWord(struct dict *vocab, int count, char *word);
int main(){
   
    int choice;
    int count = 0;
    char fileName[20] ="dict.dat";
    struct dict vocab[50];
    char word[30];
   
    count = readFile(fileName, vocab);
   
    do{
        choice = menu();
        switch(choice){
                      case 1:vocab[count++] = inputVocab();
                              break;
                      case 2:displayVocab(vocab, count);
                              break;
                      case 3:printf("nhap vao 1 tu: ");
                              fflush(stdin);
                              gets(word);
                              int vt;
                              vt = searchWord(vocab, count, word);
                              if(vt == -1)
                                    printf("khong tim thay tu ban vua nhap!\n");
                              else
                                  printf("tu ban vua nhap co trong file!\n");
                              break;
        }
    }while(choice != 4);
    writeFile(fileName, count, vocab);
    fflush(stdin);
    getchar();
}
int menu(){
    printf("\t\tDICTIONARY\n");
    printf("==============================\n");
    printf("1. Add new word\n");
    printf("2. List all\n");
    printf("3. Search\n");
    printf("4. Exit\n");
    printf("==============================\n");
    printf("chon: ");
    int choice;
    while(1){
            fflush(stdin);
            scanf("%d", &choice);
            if(choice < 1 || choice > 4){
                      printf("ban da nhap sai!!!");
            }
            else
                      break;
    }
    return choice;
}
struct dict inputVocab(){
    struct dict vocab;
    printf("Tu: ");
    fflush(stdin);
    gets(vocab.word);
    printf("Nghia: ");
    gets(vocab.description);
    printf("danh tu or dong tu or tinh tu('n','v','a'): ");
    scanf("%c", &vocab.type);
    return vocab;
}
int writeFile(char *fileName, int count, struct dict *vocab){
    FILE *f;
    f = fopen(fileName, "wb");
    if(f == NULL)
        return 0;
    fwrite(&count, sizeof(int), 1, f);
    fwrite(vocab, sizeof(struct dict), count, f);
    fclose(f);
}
int readFile(char *fileName, struct dict *vocab){
    FILE *f;
    f = fopen(fileName, "rb");
    if(f == NULL)
        return 0;
    int m;
    fread(&m, sizeof(int), 1, f);
    fread(vocab, sizeof(struct dict), m, f);
    fclose(f);
    return m;
}
void showLine(){
    char word[30] = "------------------------";
    char description[50] = "------------------------------------";
    printf("+-%-1s-+-%-24s-+-%-36s-+-%-6s-+","-", word, description, "------");
}
void showHeader(){
    showLine();
    printf("| %-1s | %-24s | %-36s | %-6s |","#","word","description"," type");
}
void displayVocab(struct dict *vocab, int count){
    int i;
    showHeader();
    for(i = 0; i < count; i++){
          showLine();
          printf("| %-1d | %-24s | %-36s | %-6c |", i+1, vocab[i].word, vocab[i].description, vocab[i].type);
    }
    showLine();
}
int searchWord(struct dict *vocab, int count, char *word){
    int i;
    for(i = 0; i < count; i++)
          if(strcmp(vocab[i].word, word) == 0){
                                  return i;
                                  break;
          }
          return -1;
}


dathl_c00493
dathl_c00493
Mod
Mod

Tổng số bài gửi : 28
Ngày tham gia : 10/12/2010
Tuổi : 33
Đến từ Đến từ : THAI BINH

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Người chơi

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by TidusAnhTu Sat Jan 08, 2011 7:04 pm

Bài 10 giống đề 3 Assig nhỉ... sao ko thêm cái setting nữa bác
TidusAnhTu
TidusAnhTu
Thành viên cấp 2
Thành viên cấp 2

Tổng số bài gửi : 144
Ngày tham gia : 05/12/2010
Tuổi : 34
Đến từ Đến từ : Hà Nội Ciudad

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Trọng tài

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by AiNq_C00498 Sat Jan 08, 2011 9:48 pm

Bạn Tidus làm được bài nào rồi post cho anh em tham khảo với!!
AiNq_C00498
AiNq_C00498
Mod
Mod

Tổng số bài gửi : 69
Ngày tham gia : 11/12/2010
Tuổi : 40
Đến từ Đến từ : XM

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by dathl_c00493 Sat Jan 08, 2011 9:54 pm

Đề bài chỉ có vậy thôi! Làm thêm thầy trử điểm mất Bai tap lab 10 908292
dathl_c00493
dathl_c00493
Mod
Mod

Tổng số bài gửi : 28
Ngày tham gia : 10/12/2010
Tuổi : 33
Đến từ Đến từ : THAI BINH

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Người chơi

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by TidusAnhTu Sat Jan 08, 2011 10:41 pm

AiNq_C00498 đã viết:Bạn Tidus làm được bài nào rồi post cho anh em tham khảo với!!

chưa làm bài nào cả Bai tap lab 10 943887 Bai tap lab 10 943887 Bai tap lab 10 943887 Bai tap lab 10 943887 Bai tap lab 10 943887 Bai tap lab 10 943887

ak mà sao lên CMS lẫn mail dều ko thấy bài Lab10 nào nhỉ Bai tap lab 10 909785 Bai tap lab 10 909785 Bai tap lab 10 909785 Bai tap lab 10 909785

PS: Mod nào thấy bài nào hay thi pick lên chú ý cho ae dễ tìm nhé
TidusAnhTu
TidusAnhTu
Thành viên cấp 2
Thành viên cấp 2

Tổng số bài gửi : 144
Ngày tham gia : 05/12/2010
Tuổi : 34
Đến từ Đến từ : Hà Nội Ciudad

Thành viên FAT3-T1010I
HP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
MP:
Bai tap lab 10 Left_bar_bleue50/50Bai tap lab 10 Empty_bar_bleue  (50/50)
Quyền hạn: Trọng tài

Về Đầu Trang Go down

Bai tap lab 10 Empty Re: Bai tap lab 10

Bài gửi by Sponsored content


Sponsored content


Về Đầu Trang Go down

Về Đầu Trang


 
Permissions in this forum:
Bạn không có quyền trả lời bài viết