Originariamente inviato da Linusss
Allora la parola + lunga che va a finire nella stringa in questione è Giù, ma normalemnte ci vanno i caratteri premuti...che sono quindi di un solo carattere.
Quindi stringa[4] dovrebbe bastare, ma non riesco ad inserire un solo carattere come si deve, infatti quando vado a rileggere i caratteri che ho digitato sembrano un po' a casaccio.
Così è ok :
codice:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>

/*STRUTTURA DEGLI ELEMENTI DELLA LISTA*/

typedef struct buffer
{
	char stringa[6];		/* Alloco staticamente la dimensione della stringa */
	struct buffer *pun;
} buff;

/*------------------------------------*/

typedef buff *pbuff;
void showlist( pbuff );
void savelist( pbuff );

int main()
{
	char c;
	pbuff p, ptemp;
	printf("Inserisci dei caratteri da tastiera,"\
	" premi ESC quando hai finito.\n\n");
	p = (pbuff)malloc( sizeof(buff) );
	p->pun = NULL;
	ptemp = p;
	
	while( c!=27 && c!=13 )
	{
		c = getch();
		if( c<=0 || c>31 ) /* Ignora se non ACII */
		{
			if( c<=0 )
			{
				c=getch();
				if( c==72 )
					strcpy( ptemp->stringa, "(Su)");
				else if( c==80 )
					strcpy( ptemp->stringa, "(Gi—)");
				else if( c==75 )
					strcpy( ptemp->stringa, "(Sx)");
				else if (c==77)
					strcpy( ptemp->stringa, "(Dx)");
				else
					strcpy( ptemp->stringa, "(?)");
			}
			else
			{
				ptemp->stringa[0] = c;
				ptemp->stringa[1] = '\0'; /* Aggiungo un terminatore */
			}
			/* Echo dei tasti premuti */
			printf("%s", ptemp->stringa);
			
			ptemp->pun=(pbuff)malloc(sizeof(buff));
			ptemp=ptemp->pun;
		}
		/* delay(150); non supportata dai miei compilatori :) */
	}
	ptemp->pun=NULL;
	ptemp = p;
	do
	{
		clrscr();
		printf("\n\t  ============MENU==========\n\t"\
		"  1) Vedi caratteri digitati\n\t"\
		"  2) Salva su file\n\tESC) Esci\n\n");
		c=getch();
		switch(c)
		{
			case 49 : showlist( ptemp ); break;
/*			case 50 : savelist( ptemp ); break; */
		}
		/* delay(150); non supportata dai miei compilatori :) */
	}
	while( c != 27 );
	return EXIT_SUCCESS;
}

void showlist(pbuff primoel)
{
	if( primoel->pun != NULL)
	{
		printf("I caratteri digitati sono: \n");
		while(primoel->pun != NULL)
		{
			printf("%s-->", primoel->stringa);
			primoel = primoel->pun;
		}
		printf("NULL\n");
	}
	else
	{
		printf("Nessun carattere digitato.\n");
	}	
	printf("\n\nPremi un tasto.\n");
	getch();	
}
Dov'era il problema che riscontravi ? :master: