第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于C語言里面文件的寫入和讀出問題

關(guān)于C語言里面文件的寫入和讀出問題

C
Camel97 2016-01-27 13:07:22
/*運行程序按1可以創(chuàng)建并且在一個文本文件里寫入保存數(shù)據(jù),再重新運行,按3,無法讀出,而且原文本文件的內(nèi)容都空了*/#include<stdio.h>#include<stdlib.h>#include<math.h>#define N 100struct product{ int num; ? ? ? ? ? ? ? ? ? ? ? //設(shè)備編號 char type[20]; ? ? ? ? ? ? //設(shè)備類 型};FILE *fp;void input(struct product *p);void scan(struct product *p);?int system(const char *string);int main(){ struct product pro[N]; int i; int number=0; if((fp=fopen("test1.txt","wt"))==NULL) { printf("不能打開文件.\n"); exit(1); } fwrite(&number,sizeof(int),1,fp); fclose(fp); printf("* 1.添加新設(shè)備 ? ? ? ? ? ? ? ? ? ? ? ?3.瀏覽設(shè)備信息 ? ? ? ? ?*\n"); printf("請用數(shù)字選擇你需要的功能:"); scanf("%d",&i); system("cls"); ? ? ? ? ? ? ? ? ?//清屏操作 switch(i) { case 1: input(pro); break; case 3: scan(pro); break; } return 0;}void input(struct product *p) ? ? ? ? ? ? ? //寫入{ char str[20]; int n; if((fp=fopen("test1.txt","wt+"))==NULL) { printf("不能打開文件.\n"); exit(1); } rewind(fp); fread(&n,sizeof(int),1,fp); n++; rewind(fp); fwrite(&n,sizeof(int),1,fp); fclose(fp); if((fp=fopen("test1.txt","at+"))==NULL) { printf("不能打開文件.\n"); exit(1); } printf("輸入設(shè)備編號:"); scanf("%s",str); p->num=atoi(str); fwrite(&(p->num),sizeof(int),1,fp); printf("輸入設(shè)備類型:"); scanf("%s",p->type); fwrite(p->type,sizeof(char),1,fp); fclose(fp);}void scan(struct product *p) ? ? ? ? ? ? ? //瀏覽 讀出{ int i,n; int num; char type[20]; if((fp=fopen("test1.txt","rt"))==NULL) { printf("error on delete!"); exit (1); } rewind(fp); fread(&n,sizeof(int),1,fp); for(i=0;i<n;i++) { fread(&num,sizeof(int),1,fp); fread(type,sizeof(char),1,fp); printf("%d ? ?%s ? \n",num,type); } fclose(fp);}
查看完整描述

1 回答

?
慕少1414285

TA貢獻4條經(jīng)驗 獲得超0個贊

這個可以讀出

char ch;

ch=fgetc(fp);

? ? while(ch!=EOF)

{

? ? ? ? putchar(ch);

? ? ? ? ch=fgetc(fp);

? ? }


查看完整回答
反對 回復(fù) 2016-02-21
  • 1 回答
  • 0 關(guān)注
  • 1804 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號