0
Pls help
Why its giving me error ? https://sololearn.com/compiler-playground/c9a306j4GHah/?ref=app
8 Answers
+ 2
You need to cast the return of malloc()
char *in1 = (char*) malloc(13 * sizeof(char));
+ 2
All right. A few remaks should be in order before i address the logic errors in your code.
I assume that you have a running code at home. By which i mean it does compile, all includes are there, and you do have actual input and in the proper format!
Especially the latter is important because your code relies heavily on correct input which is never actually sanitised! Your program will fail on erroneous input in the while loops in "reverseDate".
To your code...
invocation of reverseDate seems all right.
ll 38, 46, and 54: strlen(X) does not compute because the char sequence is not yet null terminated! The var 'i' points at the spot you want to put the zero char. So just use X[i] = '\0';, where X means d, m, or y respectively.
L 50 is the wrong logic. All '||' should be '&&'. Think upon that for a minute!
Assuming correct input, that should fix the problem. On wrong input, the while loops will break execution once you run into memory regions you are not allowed to access resulting in SIGSEGV.
+ 2
'\0'
+ 1
It is unclear how reverseDate() is invoked. Please also provide both inputProc() and setDate().
+ 1
I updated, this your request, Ani Jona.
+ 1
L50 is end of loop, but i dont know
What last char will be (0, '\0', NULL)
Which one is it ?
+ 1
I changrd L50 to
while (*dt != NULL)
And its worked thank you
0
Your welcome :)
You could even abbreviate it further to
while(*dt) { ... }