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
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?
+ 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.
+ 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
+ 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/
+ 1
no memory is allocated for char*password so it's going to crash, Try dynamically allocate it .
+ 1
Ipang initially I was trying that with array sized 50 but unfortunately it was crashing.
+ 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).
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.
0
Hima It worked when I gave the array size as 100.still Im not sure about the reason it crashed,but it works 😅
0
What's your input for crashing the code?
0
Hima I gave multiple testcases.There was no specific input for which the program crashed.None of them were working initially.