私は現在、リストの一番上に新しい要素をconsし、リストの残りを押し戻す関数をプログラムしようとしています...誰かがこれを手伝ってくれますか? プログラムをコンパイルして実行しようとすると、プログラムが機能しません。無限ループに陥ります。何か助けはありますか?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
/* linked lists of strings */
typedef struct sll sll;
struct sll {
char *s;
sll *next;
};
/* By convention, the empty list is NULL. */
/* sll_cons : (char*, sll*) -> sll* */
/* build new list with given string at the head */
/* note: copy the given string to the list (deep copy) */
sll *sll_cons(char *s, sll *ss) {
while (ss != NULL) {
char* temp;
temp = malloc(sizeof(char)*strlen(ss->s));
temp = ss->s;
ss->s = s;
ss->next = malloc(sizeof(char)*strlen(ss->s));
ss->next->s = temp;
ss->next->next = NULL;
ss = ss->next;
}
return ss;
}