28th Dec 2024, 7:16 PM
Yaniv B
Yaniv B - avatar
8 Antworten
+ 2
You need to cast the return of malloc() char *in1 = (char*) malloc(13 * sizeof(char));
28th Dec 2024, 11:06 PM
SoloProg
SoloProg - avatar
+ 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.
29th Dec 2024, 8:54 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
'\0'
31st Dec 2024, 5:27 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
It is unclear how reverseDate() is invoked. Please also provide both inputProc() and setDate().
29th Dec 2024, 8:28 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 1
I updated, this your request, Ani Jona.
29th Dec 2024, 6:47 PM
Yaniv B
Yaniv B - avatar
+ 1
L50 is end of loop, but i dont know What last char will be (0, '\0', NULL) Which one is it ?
31st Dec 2024, 4:57 PM
Yaniv B
Yaniv B - avatar
+ 1
I changrd L50 to while (*dt != NULL) And its worked thank you
31st Dec 2024, 5:55 PM
Yaniv B
Yaniv B - avatar
0
Your welcome :) You could even abbreviate it further to while(*dt) { ... }
1st Jan 2025, 12:06 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar