Click here to Skip to main content
15,902,114 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: read a file using Readfile() Pin
Rajesh R Subramanian20-Jun-09 2:09
professionalRajesh R Subramanian20-Jun-09 2:09 
GeneralRe: read a file using Readfile() Pin
chandu00420-Jun-09 2:15
chandu00420-Jun-09 2:15 
AnswerRe: read a file using Readfile() Pin
Ozer Karaagac20-Jun-09 14:25
professionalOzer Karaagac20-Jun-09 14:25 
GeneralRe: read a file using Readfile() Pin
rahuljin20-Jun-09 1:55
rahuljin20-Jun-09 1:55 
GeneralRe: read a file using Readfile() Pin
chandu00420-Jun-09 2:06
chandu00420-Jun-09 2:06 
GeneralRe: read a file using Readfile() Pin
rahuljin20-Jun-09 3:21
rahuljin20-Jun-09 3:21 
AnswerRe: read a file using Readfile() Pin
krmed20-Jun-09 3:42
krmed20-Jun-09 3:42 
GeneralRe: read a file using Readfile() Pin
rahuljin20-Jun-09 8:13
rahuljin20-Jun-09 8:13 
thanks.

i try to write some code with readfile() for line by line read, it is working but the problem is that it does not print the very last character before the end of file ---

#include <windows.h>
#include <tchar.h>
#include <stdio.h>

#define BUFFER_SIZE 82

void main(int argc, TCHAR *argv[])
{
    HANDLE hFile; 
    DWORD dwBytesRead = 0;
    char ReadBuffer[BUFFER_SIZE] = {0}, ss[16] = {0};

    printf("\n");
   

    hFile = CreateFileA("c:\\ip.txt",               // file to open
                       GENERIC_READ,          // open for reading
                       FILE_SHARE_READ,       // share for reading
                       NULL,                  // default security
                       OPEN_EXISTING,         // existing file only
                       FILE_ATTRIBUTE_NORMAL, // normal file
                       NULL);                 // no attr. template
 
    if (hFile == INVALID_HANDLE_VALUE) 
    { 
        printf("Could not open file (error %d)\n", GetLastError());
        return; 
    }

    // Read one character less than the buffer size to save room for
    // the terminating NULL character.

    if( FALSE == ReadFile(hFile, ReadBuffer, BUFFER_SIZE-2, &dwBytesRead, NULL) )
    {
        printf("Could not read from file (error %d)\n", GetLastError());
        CloseHandle(hFile);
        return;
    }

    ReadBuffer[dwBytesRead+1]='\0';

    int i ,j;
    i = -1;
    while(ReadBuffer[i+1] != '\0')
    {
    j = -1;
    do
    {
        i++;
        j++;
        ss[j] = ReadBuffer[i];
    }while((ReadBuffer[i+1] != '\n')&&(ReadBuffer[i+1] != '\0'));
    ss[j] = '\0';
    printf("%s\n", ss);
    i++;
    }

    CloseHandle(hFile);
    return;
}

the file, i want to read, has maximum of 16 characters in a line.
GeneralRe: read a file using Readfile() Pin
krmed20-Jun-09 9:34
krmed20-Jun-09 9:34 
GeneralRe: read a file using Readfile() Pin
rahuljin20-Jun-09 22:01
rahuljin20-Jun-09 22:01 
Questionincrease the size of the DialogBox during RunTime Pin
p_196020-Jun-09 0:27
p_196020-Jun-09 0:27 
AnswerRe: increase the size of the DialogBox during RunTime Pin
Sarath C20-Jun-09 0:35
Sarath C20-Jun-09 0:35 
GeneralRe: increase the size of the DialogBox during RunTime Pin
p_196020-Jun-09 0:42
p_196020-Jun-09 0:42 
GeneralRe: increase the size of the DialogBox during RunTime Pin
p_196020-Jun-09 1:08
p_196020-Jun-09 1:08 
AnswerRe: increase the size of the DialogBox during RunTime Pin
Ozer Karaagac20-Jun-09 15:21
professionalOzer Karaagac20-Jun-09 15:21 
AnswerRe: increase the size of the DialogBox during RunTime Pin
Rajesh R Subramanian20-Jun-09 3:02
professionalRajesh R Subramanian20-Jun-09 3:02 
GeneralRe: increase the size of the DialogBox during RunTime Pin
p_196020-Jun-09 18:05
p_196020-Jun-09 18:05 
QuestionHow to close the window? Pin
Nikesh Jagtap19-Jun-09 22:07
Nikesh Jagtap19-Jun-09 22:07 
AnswerRe: How to close the window? Pin
Rajesh R Subramanian19-Jun-09 22:44
professionalRajesh R Subramanian19-Jun-09 22:44 
QuestionHow to close the window? Pin
Nikesh Jagtap19-Jun-09 22:01
Nikesh Jagtap19-Jun-09 22:01 
AnswerRe: How to close the window? Pin
Sarath C20-Jun-09 0:30
Sarath C20-Jun-09 0:30 
QuestionComboBox in WIN32 programming. Pin
birajendu19-Jun-09 20:49
birajendu19-Jun-09 20:49 
AnswerRe: ComboBox in WIN32 programming. Pin
Sarath C20-Jun-09 0:20
Sarath C20-Jun-09 0:20 
GeneralRe: ComboBox in WIN32 programming. Pin
birajendu20-Jun-09 9:03
birajendu20-Jun-09 9:03 
QuestionNeed simple way to Launch a web based Php program from Windows MFC app Pin
Stevej19-Jun-09 16:59
Stevej19-Jun-09 16:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.