Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Runtime error won't display (Windows 10)

salv0id

New Coder
Hello, first of all sorry if this is the wrong section, and second (smiley face) I'm having (probably) an issue with windows 10 and command prompt or windows powershell. I tried the code with ubuntu and the terminal actually works just fine and if the code has a problem the terminal will tell me (error like buffer overflow), but on windows the command prompt won't display the error.
The code is this

Code:
#include<stdio.h>

int main()
{
    char name[9];
    scanf("%s", name); //I didn't included the "length" because I want to see if the segmentation fault appears on win10
    printf("%s\n", name);
    return 0;
}

I know it will compile and run, but once I type more characters than what the array can hold Ubuntu will tell me about segmentation fault, but on windows it doesn't, why is that?
 
First: Errors are to be avoided rather than explored - I assume you want to make sure you will receive notification in case of error, but that is a risky way to go around, instead it is a good idea to get into a habit (however difficult it is) to handle this kind of things while coding because many errors will not trigger in most circumstances, and in many cases possibly many steps down the line making it difficult to find where the issue is based on conditions that trigger them alone.

Second: What will improve amount and quality of answers for your future questions, is adding certain information, like in this case would be instead of saying "but on windows it doesn't tell me about segmentation fault" you could say what it does on windows instead (possibly along few more test scenarios) errors, completion etc. as such information often makes providing correct answer much easier, so you are more likely to get one.

And Third: This is just a guess, have you tried checking if anything happens at $error:
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom