0

What is Wrong in my Code?

I have written a simple password validator in C.But seems like there is some error.Output is Core dump.please help me in identifying the error https://code.sololearn.com/cfth5o30SVJ2/?ref=app

30th Dec 2019, 2:51 AM
_rk
_rk - avatar
11 odpowiedzi
+ 4
I tried that code with 50 character for <password> and it works _rk Did you get any error message with 50 character length password?
30th Dec 2019, 6:37 AM
Ipang
+ 3
Line 36 char password[51]; // use char array, not char pointer // array size 51 is just for example Line 38 printf ("\nEnter password : " ); // missing semicolon at the end Line 44 if (isdigit(password[i])) // use `isdigit` directly dig_count++; } Try to make these adjustments first, and see if it works.
30th Dec 2019, 6:14 AM
Ipang
+ 3
Ipang Maninder $ingh It worked when I made this small change. char *password to char password[100] To my surprise it wasnt working even when I used char password[50] before posting this question. Here is the code https://code.sololearn.com/cfth5o30SVJ2/?ref=app
30th Dec 2019, 6:32 AM
_rk
_rk - avatar
+ 2
This code works fine on pc.it crashes on sololearn playground.i have not a great experience in c but here is an article on internet why core dump error occur in your programme.you can check here and fix it. https://www.geeksforgeeks.org/core-dump-segmentation-fault-c-cpp/amp/
30th Dec 2019, 4:49 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
no memory is allocated for char*password so it's going to crash, Try dynamically allocate it .
31st Dec 2019, 1:10 PM
Hima
Hima - avatar
+ 1
Ipang initially I was trying that with array sized 50 but unfortunately it was crashing.
31st Dec 2019, 1:14 PM
_rk
_rk - avatar
+ 1
_rk I only changed line 36 like this: char password[50]; //char password[100]; And it works, both in SoloLearn and in my phone using C4Droid. Not sure why it crashes on your part though. As long as there's more than 1 digit and 1 special character it gives "Strong" as output (in case you wonder).
31st Dec 2019, 1:23 PM
Ipang
0
Maninder $ingh I tried to trace any potential errors that could cause a core dump but didnt find any.Thats why I posted in the discussions.Anyways thanks for your reply.
30th Dec 2019, 5:11 AM
_rk
_rk - avatar
0
Hima It worked when I gave the array size as 100.still Im not sure about the reason it crashed,but it works 😅
31st Dec 2019, 1:16 PM
_rk
_rk - avatar
0
What's your input for crashing the code?
31st Dec 2019, 1:17 PM
Hima
Hima - avatar
0
Hima I gave multiple testcases.There was no specific input for which the program crashed.None of them were working initially.
31st Dec 2019, 1:24 PM
_rk
_rk - avatar