如何将文本文件中的下面内容读到 2维字符串数组中,能不能按行和列读
天气 温度 湿度 风强度 打球
sunny hot low weak yes
sunny warm low strong yes
cloud hot low weak yes
cloud warm high strong yes
rain cold high weak yes
rain warm high strong yes大家给写个程序,先谢了
天气 温度 湿度 风强度 打球
sunny hot low weak yes
sunny warm low strong yes
cloud hot low weak yes
cloud warm high strong yes
rain cold high weak yes
rain warm high strong yes大家给写个程序,先谢了
解决方案 »
- PacketOpenAdapter的问题?
- 给个思路
- 请问如何让程序不能被任务管理器退出?
- 怎么声明_RecordsetPtr 变量?为什么我的什么出错了呢?
- 向各位高手求救:VC与其它应用程序通讯,OPC、OLE或DDE都可以!谁有这方面的源代码,望不吝赐教!急急急!!!
- 请问install shield在打包后怎么样在安装目录下生成一个文件夹啊?
- 怎么创建带SS_ICON风格的CStatic?
- Hook中奇怪的MessageBox
- 在Debug版下可以运行,在Release版下一运行就出现非法操作错误,谁可以帮忙,我可以发给他源程序,自己写的代码不过十几行。
- 一个编译时候的错误,谁来帮帮我?
- ComBox的OnUpdateCmdUI的问题
- 如何改变状态栏的宽度?
struct A
{
int index;
CString str_weather;
CString str_temperature;
CString str_humidity;
CString str_wind;
BOOL b_playbool;
}*p,a[20];
CString strLine;
if(!file.Open(szFileName,CFile::modeRead,NULL))
{
char buf[100];
sprintf(buf,"无法打开文件!",szFileName);
AfxMessageBox(buf,MB_OK+MB_ICONSTOP,0);
return false;
}
fTxt.SeekToBegin(); //文件指针到头,每次读之前都要这么做
for(int i=0; i<N; i++)
fTxt.ReadString(strLine);
把fTxt全该城file
{
FILE *fin = 0; //文件指针
char *FileName = "F:\\abc.txt"; //文件路径名
char *Buff[MAX_LEN]; //指针数组
char *token; //提取出的子串
char *sep = " ,\t\n"; //根据空格,逗号,TAB等区分子串
char linebuf[MAX_LEN] = ""; //从文件中读到的每一行
int Cnt = 0; //计数器 for(Cnt = 0; Cnt < MAX_LEN; Cnt++)
{
Buff[Cnt] = NULL; //初始化指针数组 }
fin = fopen(FileName, "r"); //打开文件
if(NULL == fin)
{
printf("Can't open file");
return;
} Cnt = 0;
while(NULL != fgets(linebuf, MAXLINE, fin))
{
token = strtok(linebuf, sep);
while(NULL != token)
{
Buff[Cnt] = (char*)malloc(strlen(token) + 1);//动态分配
memset(Buff[Cnt], 0, strlen(token) + 1);
strcpy(Buff[Cnt], token);//将每一行中的每个子串存到指针数组里
printf("%s\n", Buff[Cnt]);
if(NULL != Buff[Cnt])
{
free(Buff[Cnt]);//释放
Buff[Cnt] = NULL;
}
token = strtok(NULL, sep);
Cnt++;
}
}
return;
}