Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:23:17+00:00 2026-06-13T08:23:17+00:00

I am new to C and working on making an interpreter for Scheme. I

  • 0

I am new to C and working on making an interpreter for Scheme. I am trying to get a suitable printList method to traverse through the structure.

The program takes in an input like:

(a (b c))

and internally represent it as:

[""][ ][ ]-->  [""][ ][/]
     |              |              
   ["A"][/][/]     [""][ ][ ]-->  [""][ ][/]     
                        |              |                 
                      ["B"][/][/]    ["C"][/][/]

Right now, I just want the program to take in the input, make the appropriate cell structure internally and print out the cell structure, thereby getting

(a (b c))

at the end.

Here is my struct:

typedef struct conscell *List;

struct conscell {
char symbol;
struct conscell *first;
struct conscell *rest;

};


void printList(char token[20]){
    List current = S_Expression(token, 0);

     printf("(");

printf("First Value? %c \n", current->first->symbol);
printf("Second value? %c \n", current->rest->first->first->symbol);
printf("Third value? %c \n", current->rest->first->rest->first->symbol);


printf(")");

}

In the main method, I get the first token and call:

printList(token);

I tested the values again for the sublists and I think it is working. However, I will need a method to traverse through the whole structure. Please look at my printList code again. The print calls are what I have to type, to manually get the (a (b c)) list values. So I get this output:

First value? a

First value? b

First value? c

It is what I want, but I want a method to do it using a loop, no matter how complex the structure is, also adding brackets where appropriate, so in the end, I should get:

(a (b c))

which is the same as the input.

Can anyone please help me with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:23:18+00:00Added an answer on June 13, 2026 at 8:23 am

    the type of List is a pointer of struct conscell, therefore should the malloc() in your createList function be of sizeof(struct conscell):

    List node = malloc(sizeof(struct conscell));
    

    the pointer to the structure is only 8 byte, whereas the size of the structure itself is 17 (with default padding actually 24byte):

    http://en.wikipedia.org/wiki/Data_structure_alignment

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on making a new SQLite database. Obviously for a number of
I'm making extensive use of Markdown in a new project that I'm working on,
I'm working on a new-old project... I'm making it for a different country market,
I'm rather new to C and have recently been working on making a simple
I'm new working with JSON and the getJSON function etc and I'm trying to
I am working on making my first android app. I am trying to start
I am new to Android and trying to practice by making small codes. I
I am working on making my client open another program by downloading the bytes
I am working through making cholorpleth's (a learning project I started HERE ). I
Im new to working with Domain Models so forgive me for asking an elementary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.