[Solved] Why does my program fail when my elements are more than one digit? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[Solved] Why does my program fail when my elements are more than one digit?

G'day, I'm trying to use pointers to dynamically hold an array. My program works for single digit integers, but crashes spectacularly if I input 10 or higher. I want to avoid having a fixed size array. What is your way to expand the programs ability beyond handling single digit elements? Edit: I added a multiplier to my malloc, now 4 digits fit in each element. https://code.sololearn.com/c6eQ1R7QYL7O/?ref=app

16th Feb 2022, 7:18 AM
HungryTradie
HungryTradie - avatar
2 Answers
+ 1
There is no such issue occuring in my device
16th Feb 2022, 11:15 AM
Sahil Mattoo
0
G'day Sahil Mattoo I had played around and found what I was missing. I needed to multiply the malloc by the QTY of digits I wanted my elements to be able to hold. If you want to see the error, change 👉#define QTY 4👈 to become #define QTY 1. Then run the program with some single digit integers (works fine) then with some single digit and a two digit (eg 9 5 7 11 3 0) it will crash!
16th Feb 2022, 7:07 PM
HungryTradie
HungryTradie - avatar