The variable ' str ' is being used without being defined problem

Source: Internet
Author: User

The following error occurs when working with char data in C:

Run-time Check Failure #3-the variable ' str ' is being used without being defined.

This is typically caused by not allocating storage space to the char* str when it is defined.

Such as:

char* str;

strcpy (str, "string");

The above error will occur.

But if it is defined as:

Char str[10];//Note that the string length is at least greater than one character below the string length.

strcpy (str, "string");

There will be no error.

The character space of Str can also be allocated dynamically.

char* str;

str = (char*) malloc (strlen ("string") *sizeof (char));

strcpy (str, "string");

This problem may also occur when there is an access violation occurring at the write location.

Such as:

Unhandled exception at 0x102aece9 (Msvcr80d.dll) in XX.exe: 0xC0000005: Access violation when writing to location 0x004156b4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.