fgets proplem

With this source code I am scanning for txt files in a folder called texts. I want to try to open a text file and print its contents to the screen (about a word or two). it should not take more than a 25 char string. this is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <time.h>
#include <string>

using namespace std;

char filedata[25];

string Chop(string &str) {
    string res = str;
    int len = str.length();
    if (str[len - 1] == '\r') {
        res.replace(len - 1, 1, "");
    }
    len = str.length();
    if (str[len - 1] == '\n') {
        res.replace(len - 1, 1, "");
    }
    return res;
}

void DumpEntry(_finddata_t &data) {
	fgets (filedata , 25 , data);
    string createtime(ctime(&data.time_create));
    cout << Chop(createtime) << "\t";
    cout << data.size << "\t";
	cout << filedata << "\t";
    if (data.attrib & _A_SUBDIR == _A_SUBDIR) {
        cout << "[" << data.name << "]" << endl;
    }
    else {
        cout << data.name << endl;
    }
}

int main(int argc, char *argv[])
{
	puts("The halo trial mod switcher!");
    _finddata_t data;
	int ff = _findfirst ("texts/*.txt*", &data);
    if (ff != -1) {
        int res = 0;
        while (res != -1) {
            DumpEntry(data);
            res = _findnext(ff, &data);
        }
        _findclose(ff);
    }
    system("PAUSE");
    return 0;
}


and this is my error

1>------ Build started: Project: ModSwitch, Configuration: Debug Win32 ------
1>Compiling...
1>scource code.cpp
1>c:\users\User\documents\visual studio 2008\projects\modswitch\modswitch\scource code.cpp(31) : error C2664: 'fgets' : cannot convert parameter 3 from '_finddata64i32_t' to 'FILE *'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\User\documents\visual studio 2008\projects\modswitch\modswitch\scource code.cpp(36) : warning C4554: '&' : check operator precedence for possible error; use parentheses to clarify precedence
1>Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2008\Projects\ModSwitch\ModSwitch\Debug\BuildLog.htm"
1>ModSwitch - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I have a 64 bit pc running windows vista ultimate. does anyone know how to make _finddata_t work with fgets or another way to do this?
Last edited on
Topic archived. No new replies allowed.