Neste código aparece um número a frente dos que foram digitados, alguém sabe como corrigir?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct Lista{
int num;
struct Lista *proximo;
};
struct Lista * cria(void)
{
return NULL;
}
struct Lista * add(struct Lista *l, int num)
{
struct Lista *novo = (struct Lista*)malloc(sizeof(struct Lista));
novo->num = num;
if(l == NULL)
{
novo->proximo = NULL;
return novo;
}
else
{
struct Lista *temp = l;
while(temp->proximo != NULL)
{
temp = temp->proximo;
}
novo->proximo = NULL;
temp->proximo = novo;
return l;
}
}
void list(struct Lista *l)
{
struct Lista *p;
for(p=l;p!=NULL;p=p->proximo)
{
printf("%d ", p->num);
}
}
main()
{
int num;
char *cmd;
char string_enter[50];
struct Lista *l;
l = cria();
l = add(l,num);
do
{
gets(string_enter);
cmd = strtok(string_enter," ");
num = atoi((char *)strtok(NULL," "));
if(strcmp(cmd,"add")== 0){
add(l,num);
continue;
}
else if(strcmp(cmd,"list")== 0){
list(l);
continue;
}
}while(strcmp(cmd,"end")!= 0);
system("pause");
}