C语言与SDL编程基础
1. C语言文件读取与I/O函数
在C语言中,文件读取和输入输出操作是常见的任务。以下是一个从文件中读取阿伏伽德罗常数的示例代码:
file = fopen ("newfile.txt", "r");
fscanf (file, "%s %s %s %e", junk, junk, junk, &number);
/* Read in 3 words, then the number we want */
fclose (file);
printf ("Looks like Avogadro's number is still %.4e.\n", number);
文件内容为 The file will contain Avogadro's number is 6.0230e+023. ,程序输出为:
Avogadro's number is 6.0230e+023.
Looks like Avogadro's number is still 6.0230e+023.
除了基本的 printf 和 scanf 函数,还有一些其他的I/O函数:
- sscanf :从字符数组中读取数据。例如:
sscanf (myCharArray, "%f %s", &myDouble, myWord);
/* myD
超级会员免费看
订阅专栏 解锁全文
1215

被折叠的 条评论
为什么被折叠?



