日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

mac怎么实现文件读写c语言,使用Sublime Text和Xcode在Mac上进行文件输入/输出。 C语言...

發布時間:2024/10/8 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mac怎么实现文件读写c语言,使用Sublime Text和Xcode在Mac上进行文件输入/输出。 C语言... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

f1name和f2name應的字符來存儲文件名的數組。你已經將它們定義為字符,并試圖在其中存儲字符串將調用未定義的行為,因為scanf將執行非法內存訪問。

另外,main函數的簽名應該是以下任一項。

int main(void);

int main(int argc, char *argv[]);

你應該修改你的程序

#include

#include

int main(void) {

// variable name SSN change to lowercase

int ssn, n, i;

int retval; // to save the return value of fscanf

float wages, total;

char f1name[30+1], f2name[30+1];

// define file pointers inside main

// also change the name to lowercase

FILE *f1, *f2;

scanf("%30s", f1name);

f1 = fopen(f1name, "r");

// check for error in opening file

if(f1 == NULL) {

// print error message to stderr

perror("error in opening file\n");

// handle it

}

retval = fscanf(f1, "%d", &n);

if(retval != 1) {

perror("error in reading from the file\n");

// handle it

}

for(i = 0; i < n; i++) {

retval = fscanf(f1,"%d%f", &ssn, &wages);

if(retval != 2) {

perror("error in reading from the file\n");

// handle it

}

total += wages;

}

scanf("%30s", f2name);

f2 = fopen(f2name, "w");

// check for error in opening file

if(f2 == NULL) {

// print error message to stderr

perror("error in opening file\n");

// handle it

}

// Writing to the file the average of all earnings

fprintf(f2,"%d %f", ssn, total/n);

// Closing the file

fclose(f1);

fclose(f2);

return 0;

}

總結

以上是生活随笔為你收集整理的mac怎么实现文件读写c语言,使用Sublime Text和Xcode在Mac上进行文件输入/输出。 C语言...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。