c_cpp 在c中打印类似字符串的lisp
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 在c中打印类似字符串的lisp相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <stdlib.h>
//test object for simple functional language
typedef enum
{
WindType_None,
WindType_Int,
WindType_Char,
WindType_List
} WindType;
struct WindObject
{
WindType type;
long _int;
char _char;
struct WindObject* _lst; // nests one level down.
struct WindObject* next; //next in seq
};
// creates string with windobject
struct WindObject* createString(char* code)
{
struct WindObject* wobj = malloc(sizeof(struct WindObject));
struct WindObject* objPtr = wobj;
while(*code)
{
objPtr->_char = *code;
objPtr->type = WindType_Char;
objPtr->next = malloc(sizeof(struct WindObject));
objPtr = objPtr->next;
code++;
}
objPtr->next = NULL;
return wobj;
}
//prints Wind String
void printString(struct WindObject* wobj)
{
while(wobj != NULL)
{
putc(wobj->_char, stdout);
wobj = wobj->next;
}
putc('\n', stdout);
}
int main(int argc, char const *argv[])
{
struct WindObject* string = createString("Hello!");
printString(string);
return 0;
}
以上是关于c_cpp 在c中打印类似字符串的lisp的主要内容,如果未能解决你的问题,请参考以下文章