首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

文字判定,该如何解决

2013-01-23 
文字判定要求 读取popu2000.txt 文档广州 5683062 北京 1475728 上海 1416180 成都 2365320 重庆 1189279。

文字判定
要求 读取popu2000.txt 文档

广州 5683062
 
北京 1475728
 
上海 1416180
 
成都 2365320
 
重庆 1189279
   。
    。
    。

然后将城市名放入结构体 city.name[10],人口数放入 city.popu
最后按人口数由大到小排序。。

不知到用哪个函数能判断名字 还是 数字啊~文字判定,该如何解决 
[解决办法]


#include <iostream>
#include <fstream>
#include <string>

struct City
{
char name[10];
int popu;
} city[100];


int main()
{
using namespace std;
string name;
int value, index = 0;

ifstream ifs("filename.txt");
if (ifs) {
while (ifs >> name >> value) {
strcpy(city[index].name, name.c_str());
city[index++].popu = value;
}
}

}

[解决办法]
int i;
0==sscanf("广州","%d",&i)
1==sscanf("5683062","%d",&i)

热点排行