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

  • SEARCH
  • Home
  • 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 7278693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:54:33+00:00 2026-05-28T22:54:33+00:00

I am using this simple..yet getting error. to read a directory path from console

  • 0

I am using this simple..yet getting error.

to read a directory path from console window and then printing the path in window..

please do check why am getting unhandled exception error:

Error:Unhandled exception at 0x1029984f (msvcr90d.dll) in new_one.exe: 0xC0000005: Access violation reading location 0x745c3a46.

#include "stdafx.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#define MAX_PATH_LENGTH 256 
int main(int argc, char *argv[])
{
int i;
int pathlength=100;
char *path=(char *)malloc(MAX_PATH_LENGTH);
free(path);
printf("Enter the path:");
scanf("%s",&path); 
printf("%s",path);
getchar();
return 0;
} 

Still i get the sam eexception..please give me any suggestion

  • 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-28T22:54:35+00:00Added an answer on May 28, 2026 at 10:54 pm
    char *path;
    

    Is not allocated any memory. You are writing to an unallocated pointer variable resulting in Undefined Behavior, which shows up as an segmentation fault.

    You could solve the problem in two ways:

    Allocating object on stack:

    Create path as an array locally on stack, such as:

    #define MAX_PATH_LENGTH 256
    
    char path[MAX_PATH_LENGTH];
    

    Dynamic Memory allocation:

    #define MAX_PATH_LENGTH 256
    
    char *path=(char *)malloc(MAX_PATH_LENGTH);
    

    If you use the second approach, You need to explicitly, free the allocated memory after your usage:

    free(path);
    

    Usually, avoid using dynamic allocations(second approach) unless the memory requirement is too large to be allocated on stack.

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

Sidebar

Related Questions

Hey all, I am trying to accomplish something very simple yet getting an error
I'm using this simple regular expression to validate a hex string: ^[A-Fa-f0-9]{16}$ As you
I'm using this simple function: def print_players(players): tot = 1 for p in players:
Ho to make this simple xml with php using DOM? Full code will be
I'm using this jQuery urlencode and urldecode plugin - very simple and easy to
Can anybody help me with this simple code?? #include <iostream> using namespace std; void
I'm trying to develop a simple kernel using TASM, using this code: ; beroset.asm
What's the fastest way using either DOS scripting or PowerShell to run this simple
After loading a PHP template (using jQuery's load function), this simple script won't make
This is simple text detection video made using an opencv. Any ideas how was

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.