Thread: Errors in my C program

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    31

    Errors in my C program

    Code:
    void printListReversed(node *list) {113
    114
    115
    116  if (list!=NULL) return; 
    117
    118   double x,y;
    119   list = list->next;
    120
    121   do
    122     {
    123       printf("%lf \t %lf",x,y);
    124       list= list->prev;
    125     } while (list->next !=NULL){
    126
    127
    128
    129     /* list = list->next; list->next */
    130  }
    131
    132
    133 }
    Code:
     ~/> icc -ansi -Wall -c -o list.o list.c
    
    list.c(125): error: expected a ";"
           } while (list->next !=NULL){
                                      ^
    list.c(133): warning #12: parsing restarts here after previous syntax error
       }
       ^
    
    
    compilation aborted for list.c (code 2)
    Hello, I am having errors in my code and I can't seem to figure out.
    anyone can help, please.

    Thanks in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,508
    That opening brace should have been a semi-colon as you're ending the do while loop.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Sep 2018
    Posts
    31

    Post something like this

    Quote Originally Posted by laserlight View Post
    That opening brace should have been a semi-colon as you're ending the do while loop.

    Code:
      do     
    122          ;
    123       printf("%lf \t %lf",x,y);
    124       list= list->prev;
    125     } while (list->next !=NULL){
    126
    127
    128
    129     /* list = list->next; list->next */
    130  }
    131
    132
    133 }

  4. #4
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,728
    You can do either or, but not both at the same time:
    Code:
    do {
        ...
    } while (...);
    Code:
    while (...) {
        ...
    }
    Devoted my life to programming...

  5. #5
    Registered User
    Join Date
    Nov 2018
    Posts
    21
    Quote Originally Posted by erald23 View Post
    Code:
    void printListReversed(node *list) {113
    114
    115
    116  if (list!=NULL) return; 
    117
    maybe after all of them mistakes pointed out , I am putting your logic to question. your first check is for if list Not Null then return , causing it to leave your function,

    then here,

    Quote Originally Posted by erald23 View Post
    118 double x,y;
    119 list = list->next;
    120
    121 do
    122 {
    123 printf("%lf \t %lf",x,y);
    124 list= list->prev;
    125 } while (list->next !=NULL){
    126
    127
    128
    129 /* list = list->next; list->next */
    130 }
    131
    132
    133 }
    your second operation on your list is to iterate through your list until it is NULL.

    do you see the conflict within your function?
    Last edited by poorboy; 11-29-2018 at 08:15 AM.

  6. #6
    Registered User
    Join Date
    Dec 2018
    Posts
    8
    Quote Originally Posted by erald23 View Post
    [CODE]void printListReversed(node *list) {113
    114
    115
    116 if (list!=NULL) return;
    117
    118
    This line doesn't make sense as far as I can see: Following lines of code will only be executed if list is a NULL-pointer. but if list is NULL, there won't be a
    list->next etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Some errors in my Program
    By Steveqb14 in forum C Programming
    Replies: 2
    Last Post: 04-14-2014, 09:17 AM
  2. The last few errors in my first program!
    By krazymanrebirth in forum C Programming
    Replies: 23
    Last Post: 09-15-2009, 12:02 PM
  3. errors in c program
    By akshara.sinha in forum C Programming
    Replies: 1
    Last Post: 12-22-2007, 06:15 PM
  4. Errors in my program
    By gjack72 in forum C++ Programming
    Replies: 3
    Last Post: 11-17-2005, 02:45 PM
  5. Errors with program
    By nizbit in forum C Programming
    Replies: 37
    Last Post: 12-19-2004, 09:56 PM

Tags for this Thread