| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1264 人关注过本帖
标题:请大神帮忙看下,问题出在哪了?读取目录下文件内容,怎么调也不对,快疯了
取消只看楼主 加入收藏
sophia536
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-10
收藏
 问题点数:0 回复次数:2 
请大神帮忙看下,问题出在哪了?读取目录下文件内容,怎么调也不对,快疯了
程序代码如下:
程序代码:
#include <stdio.h> 
#include <uf.h>
#include <uf_defs.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_styler.h>
#include <uf_mb.h> 
#include "section.h"
#include <io.h> 
#include <uf_ui_types.h>
#include <stdarg.h>
//#include <fstream>
//using namespace std;

static void do_api ( int dialog_id)
{

    int i;
    double quantity,height,h_calc;
    char msg[256+1],path[200],cout,line[1024],*p,*buf;
    struct _finddata_t findData;  
    intptr_t handle;
    long lfDir;
    FILE *fp;  
    int file_size;
    char *tmp;

    UF_UI_open_listing_window();

     get_real_data( dialog_id,SECTION_QUANTITY,&quantity );
     get_real_data( dialog_id,SECTION_HEIGHT,&height );
     get_string_data( dialog_id,SECTION_PATH,&path );
       
     h_calc=height/(quantity-1);
     strcat(path, "\\*.*"); 

     ///* 用于测试
     //UF_UI_open_listing_window();
     //sprintf(msg,"%s \n",path);   
     //UF_UI_write_listing_window(msg);

     /////* 用于测试
     //UF_UI_open_listing_window();
     //sprintf(msg,"quantity=%f  ,height=%f ,section height=%f \n",quantity,height,h_calc);   
     //UF_UI_write_listing_window(msg);

     handle = _findfirst(path, &findData);

     if((lfDir = _findfirst(path,&findData))==-1l)
      {
          for(i=1;i<20;i++)
          ECHO("No file is found\n");
     }
     else
     {
      
          sprintf(msg,"file list:\n");
          UF_UI_write_listing_window(msg);
      }
     do{
        if(strcmp(findData.name, ".") != 0 && strcmp(findData.name, "..") != 0)
         {
          sprintf(msg,"%s \n",findData.name);   
          UF_UI_write_listing_window(msg);

          fp = fopen(findData.name,"r");

          fseek( fp , 0 , SEEK_END );          
          file_size = ftell( fp );
          fseek( fp , 0 , SEEK_SET);
          tmp =  (char *)malloc( file_size * sizeof( char ) );
          fread( tmp , file_size , sizeof(char) , fp);
          sprintf(msg,"%s \n",tmp);
          UF_UI_write_listing_window(msg);

          buf=(char*)malloc(1024*sizeof(char));
          while(1) {
              p=fgets(buf, 1024, fp);
              sprintf(msg,"%s \n",buf);   
              UF_UI_write_listing_window(msg);
          
          if(!p)
          break;
          }
          fclose(fp);
         }
       }while( _findnext( lfDir, &findData ) == 0 );
     
    _findclose(handle);
     UF_terminate ();

     return (UF_UI_CB_EXIT_DIALOG);                           

}


这个在UG中做的开发,用的C编程,编译不报错,但是就是不出结果,输出完文件名就没了,请大神帮忙看看
搜索更多相关主题的帖子: include char path tmp sprintf 
2018-04-10 17:46
sophia536
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-10
收藏
得分:0 
回复 楼主 sophia536
里面有些函数和子程序没详细贴出来,主要是遍历目录文件、读取文件内容这部分有问题
2018-04-10 17:47
sophia536
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2018-4-10
收藏
得分:0 
找到问题了,解决了
2018-04-14 15:38
快速回复:请大神帮忙看下,问题出在哪了?读取目录下文件内容,怎么调也不对,快 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016290 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved