0

why does this code always cause Segmentation fault......

may be it is able to run on sololearn normally but as long as on my IDE,it gets mad🌚 https://code.sololearn.com/cwPPeirS6oyE/?ref=app

22nd Jan 2019, 7:51 AM
HZCK_Mi Sa Pon
HZCK_Mi Sa Pon - avatar
8 Réponses
+ 3
You are using mid as the length of store, but you haven't initialized it. mid and sbs are basically unused here. instead of inn - (inn/10)*10, you can use inn%10.
22nd Jan 2019, 8:22 AM
Zen
Zen - avatar
+ 3
It seems like you want to sum the digits of your input, you don't need store at all, just do the sum right away.
22nd Jan 2019, 8:44 AM
Zen
Zen - avatar
+ 1
Sure, but you don't really need pointers here. Also, you have to understand that you need to assign a value to a variable before using it, otherwise it will contain a garbage value that doesn't correspond to anything. Remove sbs, store, and cont, and do the sum with deld1 in your first loop.
22nd Jan 2019, 9:22 AM
Zen
Zen - avatar
+ 1
If you're still stuck, here is the solution: https://code.sololearn.com/cgLvmu38kRwA/?ref=app
23rd Jan 2019, 1:05 PM
Zen
Zen - avatar
0
Zen as you can see the new edition,i change it as you told me but it don't output anything now.....
22nd Jan 2019, 8:40 AM
HZCK_Mi Sa Pon
HZCK_Mi Sa Pon - avatar
0
Zen Yeah, you're right, but from this code i want to know the reason for which My code make this mistake,And the true use of the pointers. May I take more of your time?
22nd Jan 2019, 9:17 AM
HZCK_Mi Sa Pon
HZCK_Mi Sa Pon - avatar
0
thanks a lot for your patience:)
22nd Jan 2019, 10:14 AM
HZCK_Mi Sa Pon
HZCK_Mi Sa Pon - avatar
0
Zen thanks a lot for your patience.your code is really helpful:)
27th Jan 2019, 9:47 AM
HZCK_Mi Sa Pon
HZCK_Mi Sa Pon - avatar