Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 836585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:00:27+00:00 2026-05-15T05:00:27+00:00

I know what is my mistake can’t figer how to solve it. Im writing

  • 0

I know what is my mistake can’t figer how to solve it.

Im writing an winAPI that counts how many ‘a’ characters are found is a givien file.
Im still getting the error ” subscript requires array or pointer ” (please find the comment in the code)

#include "stdafx.h"
#include <windows.h>


int _tmain(int argc, _TCHAR* argv[])
{
    WCHAR str=L'a';
    HANDLE A;
    TCHAR *fn;

    fn=L"d:\\test.txt";
    A= CreateFile(fn,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

    if(A==INVALID_HANDLE_VALUE)
    {
        _tprintf(L"cannot open file \n");
    }

    else
    {
        DWORD really;
        int countletter;
        int stringsize;
        do
        {
            BYTE x[1024];


            ReadFile(A,x,1024,&really,NULL);
            stringsize = sizeof(really);
            for(int i =0;i<stringsize;i++)
            {

                if(really[i]==str)   //here Im getting the error
                    countletter++;
            }
        }while(really==1024);

            CloseHandle(A);
            _tprintf(L"NUmbers of A's found is %d \n",countletter);
    }

    return 0;
}

now I know I can’t make comparesion between array and a WCHAR but hw to fix it ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:00:28+00:00Added an answer on May 15, 2026 at 5:00 am

    ReadFile() puts the data into the second parameter, in your case x.

    In your code, really is the number of bytes read. It’s just a number. You can’t put an subscript on a plain number, thus the error message.

    So change

    if(really[i]==str)
    

    To

    if (x[i] == str) 
    

    But you’re going to hit another problem:

    DWORD really;
    int countletter;
    int stringsize;
    
    do {
        BYTE x[1024];
    
        bool bResult = ReadFile(A, x, 1024, &really, NULL); // must save the result
        if (bResult) 
            break; // Error!
    
        // stringsize = sizeof(really); // <== NO NO NO will always return 8
        stringsize = really;  // this is what you need
    
        for (int i = 0; i < stringsize; i++)
        {
            if(x[i] == str)
                countletter++;
        }
    } while (really == 1024);
    

    You’ll need some error handling of course, and you really need meaningful variable names. Your problem would have been obvious if you had used inputBuffer and bytesRead instead of x and really.

    Edited to add:

    Your comment is correct, my previous edit went too far. It’s true that the next-to-last read should return 1024 bytes, while the last will return < 1024. But I would still check for bytesRead == 0 right after the read, because it’s easier to understand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

can anyone see where i made a mistake here? I know that the algorithm
By mistake I think touched some file (dont know the name) in the following
I know that this has been discussed lot of times. I just can't understand
Can anyone please let me know where I made a mistake in this code?
Yes, I know that UndecidableInstances can be bad. I really tried hard to design
I know I can use while(dr.Read()){...} but that loops every field on my table,
I do not know if I awake stupid but I can not solve this
I don't know if I can ask this question here. I usually mistake, but...
I know that this question is asked for many times but i am working
its kind of silly question. but i dont know what mistake i am making.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.