"Stack around the variable was corrupted" error

Anil

I'm trying to read a char value using fgets as follows:

int main() {
    char m_cityCharCount;

    // Input the number of cities
    fgets(&m_cityCharCount, 4, stdin);
    return 0;
}

Visual Studio returns this error after the code is executed - Stack around the variable m_cityCharCount was corrupted

Is there something I can do about it?

P. Dmitry

First parameter of fgets() is pointer on buffer (size of it should be great or equals than second parameter. But sizeof(char) == 1)

int main() {
    char m_cityCharCount[4];

   // Input the number of cities
   fgets(m_cityCharCount, 4, stdin);
   return 0;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related