在C 中进行文件处理以读取两个整数
File handling in c++ to read two integers
如何从c 中逗号分隔的文件中读取两个整数?例如5,6写在文件中,我如何读这两个整数?
/* sscanf example */
#include <stdio.h>
int main ()
{
char sentence []="Rudolph is 12 years old";
char str [20];
char str2 [20];
int i;
sscanf (sentence,"%s %s %d",str,str2,&i);
//str=Rudolph
//str2=is
//i=12
printf ("%s %s -> %dn",str,str2,i);
return 0;
}
输出:鲁道夫是 -> 12
/* sscanf example */
#include <stdio.h>
int main ()
{
char sentence []="5,6,7";
char str [20];
char str2 [20];
int i,j,k;
sscanf (sentence,"%d %*c %d %*c %d",&i,&j,&k);
printf ("%d %d %dn",i,j,k);
return 0;
}
输出:5 6 7
相关文章:
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 比较C++中两个整数的最有效和最干净的方法是什么?
- 如何将字符串和整数读取到两个单独的动态数组中的程序编写?
- 为什么将两个浮点数相加会得到一个整数C++?
- 从两个 4x64 位整数数组中获取取模
- 为什么 Clang 和 GCC 中两个无符号整数之和的结果类型不同
- 比较两个整数在C++中与未知 int 类型的相等性
- 创建整数的 2D 数组,该数组将使用两个函数用随机数填充矩阵.我做错了什么?
- 如何组合两个整数向量
- 在两个整数之间交换最右边的N位
- 打印出两个整数之间的偶数
- 为什么将两个总和为 32k >整数相加时得到负数?
- C++ 两个线程,共享几个整数变量
- Python 等效代码,可像C++一样直接附加两个整数
- 是否有任何内置函数可以检查给定的两个数字在给定整数数组中的顺序是否相同?
- 移位运算符如何在查找两个整数中的不同位数?
- 如何安全地比较两个无符号整数计数器?
- 添加两个二进制数(整数数组)
- 运算符"|"如何计算两个整数?
- 如何找出在两个整数的乘积中设置了多少位(等于 1)