what is wrong in this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

what is wrong in this code

https://code.sololearn.com/c1WiMsytchSX/#c This is supposed to print an array of the numbers between the symbols(+and -) in <inp>. However it prints the first number(123), 4 times when compiled in 'dos box' and gives no output when compiled in the 'solo learn code playground'.Please help

23rd Apr 2019, 6:09 AM
Siddharth Acharya
Siddharth Acharya - avatar
3 Answers
+ 1
Add getch (); in the last
23rd Apr 2019, 6:57 AM
Prerak Gada
Prerak Gada - avatar
+ 5
Siddharth Acharya it seems there are so many points to be updated into this code... let me update this comment itself by going through each line of your code: 1.... for(k = 0; k<=40; k++)// update this code... k is started from zero, then it should be like k<40 instead of <=... best way to do is find 13 as length of inp using strlen(inp) 2... you are doing arr[ind]=intc(slice(inp,s,k-1)); this ask for input in the range 0 and -1 in case of k as 0... this should be updated 3... Major issue is function slice... you are doing return retu; ... where retu is local to function and it cannot be referred out side of function... you should declare it as static like static char retu[40]; if you wanna return it from function 4.... you should not compare int with null... line else if(inp[k] != NULL) is not required when you updated as per point 1.. just use else instead of condition
23rd Apr 2019, 7:46 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 4
Siddharth Acharya 5... you cannot compare int with nulll like I said in point 4... so, for(i = 0; arr[i] != NULL; i++) is not proper.... use i<ind in for loop as you are maintaing ind variable... if it is not you want to use, find strlen (arr) and use that length into for loop condition.. 6... in slice function, && should be used for and condition into for loop... change below line : for(i = 0; i>=a & i<=b; i++) Update code accordingly and comment here if you still don't get desired output
23rd Apr 2019, 7:58 AM
Ketan Lalcheta
Ketan Lalcheta - avatar