Check palindrome words using double linked list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Check palindrome words using double linked list

C https://code.sololearn.com/c0BWY8kr5iZk/?ref=app

24th Mar 2021, 12:14 PM
Vedika Agrawal
Vedika Agrawal - avatar
10 Answers
+ 2
Vedika Agrawal quoted from my previous answer "the type of `k` should be char*" You have set the type of `k` to char. Also quoted from my previous answer "You might wanna try `*k != '\0'` In your code, you written `k != 0` (you forgot the dereference operator) Also, on line 72, why are you passing the character 'k'. You have to pass *the dereferenced value of variable k*. And there is no need of typecasting to `short` The final for-loop body will be ``` for(char* k =n; *k != '\0'; k++) appendNode(&start, &end, *k); ```
24th Mar 2021, 2:50 PM
XXX
XXX - avatar
+ 2
[Part 1 of answer] Have you written the code? Because in some places, it looks like it has been written by someone who knows a little bit of C, and in others, it looks like it has been written someone who is new to C and is totally confused. Anyways, there are many errors in the code: 1. Line 20: you need to give the struct keyword when you’re typedef-ing structs. So it should be typedef struct node *ptrNode; 2. Line 67: what is `char long`? 3. This is the weirdest part. On line 70, you are taking char input. On line 71, you are assigning it to a variable of type int. On line 72, you are typecasting it to short and passing it to function that takes int. Also, from what it looks like, each node of the linked list represents a character of the string. So why are you taking 1 character input only, and treating it as if it is a number (dividing and modding by 10)? This makes no sense.
24th Mar 2021, 1:04 PM
XXX
XXX - avatar
+ 2
[Part 2 of answer] To fix the code: 1. Fix the 1st point mentioned above 2. On line 67, make a variable that will store a string. char n[100]; 3. Line 70, take string input into `n` 4. Line 71, change the for loop to iterate through each character of `n` 5. Line 72, pass the character as the last argument 6. Line 32, change type of `n` to char. 7. Line 74, change format specifier to output `n` as string
24th Mar 2021, 1:04 PM
XXX
XXX - avatar
+ 2
On line 70: the format specifier to take string input is not %str, it is %s. Also, you don't need to pass a pointer to the char array while taking input. Just pass the variable having the char array - change &n to n. And what are you even doing on line 71 and 72? On line 71: for (int k = n; k='\0'; k++) here, the type of `k` should be char*. You should not assign a value of type `char*` to a variable of type `int`. Then, `k='\0'` is not a condition. You might wanna try `*k != '\0'`. On line 72: Why are you passign (k == '\0') as the last argument? Just simply pass the character `k` points to, that is, pass `*k` as the last argument.
24th Mar 2021, 2:04 PM
XXX
XXX - avatar
+ 1
Vedika Agrawal looks like my suspicion was right. You did not make the code yourself. Also explains why most of the program was well written and the rest of it was just pure stupidity. I am not a professional coder and have many years before I can become one, so I don't know how much my advice counts. But being okay with someone else making codes for you will not help you get better. You could have atleast understood the code and tried remaking it yourself, but you thought that asking another question and having another person fix the code for you was a better option. Please start writing your code yourself or you will be dependant on some fool like me to tell you the same thing 5 times so that you can get your code to work. I don't like ranting like this but it makes me angry that I wasted 15 minutes helping someone fix a code they didn't even write themselves. Happy coding!
24th Mar 2021, 6:19 PM
XXX
XXX - avatar
0
Just have a look plz... As your suggestions I have done with the changes. But it is showing every word as palindrome...
24th Mar 2021, 1:42 PM
Vedika Agrawal
Vedika Agrawal - avatar
24th Mar 2021, 1:52 PM
Vedika Agrawal
Vedika Agrawal - avatar
0
https://code.sololearn.com/cEr3Nu7ZUO54/?ref=app
24th Mar 2021, 2:30 PM
Vedika Agrawal
Vedika Agrawal - avatar
0
??
24th Mar 2021, 2:30 PM
Vedika Agrawal
Vedika Agrawal - avatar
0
Thanks a lot...👍
24th Mar 2021, 2:56 PM
Vedika Agrawal
Vedika Agrawal - avatar