All pastes #64779 Raw Edit

Miscellany

public c v1 · immutable
#64779 ·published 2006-06-12 10:00 UTC
rendered paste body
MAIN DEL PROGRAMMA#############################################include <stdlib.h>#include <stdio.h>#include <string.h>#include "m_list.h"#include "header.h"#define MAX_LEN 20typedef struct nodo{	char nome[40];	float voto;	struct nodo *next;}nodo;void leggi(char *file, nodo *lista){FILE *fp;char buf[255],nome[40];float voto;nodo *tmp;				fp = m_fopen(file,"r");		while (!feof(fp)){		fgets(buf,sizeof(buf),fp);			sscanf(buf,"%s %f", nome, &voto);				tmp=m_alloc(sizeof(tmp));				strncpy(tmp->nome, nome, sizeof(nome));		tmp->voto=voto;				printf("%s\t%2.1f\n", tmp->nome, tmp->voto);				add_nodo (&lista,&tmp);		//print_lista(lista);		//printf("%s %2.2f\n", nome, voto);					}return;}	int main (void){char com[MAX_LEN],bus[MAX_LEN];nodo *lista=NULL;	while(1){	printf("sh:~$ ");		scanf("%s", com);		if (strcmp(com, "exit")==0) exit(0);	else scanf("%s", bus);	//printf("%s", bus);	//printf("%s %s", com, bus);	if (strcmp(com, "leggi")==0) leggi(bus,lista);			//if (strncmp(com, "scriviN")==0) leggi(bus);	//if (strncmp(com, "scriviV")==0) leggi(bus);	else fprintf(stderr, "Command not found.\n");}	printf("com:%s\nbus:%s\nSei contento???", com, bus);	return 0;}##############################################################################Header##########################struct node {  void *item;  uint item_size;  struct node *next;};typedef struct node *NODE;void *m_alloc(int n){  NODE tmp;	  tmp = (void *)malloc(n);  if (tmp == NULL) {    fprintf(stderr, "ERRORE: memoria insufficiente.\n");    exit (1);  }  return (tmp);}void add_nodo(NODE *lista, NODE *tmp){NODE *aus, tmp0;tmp0=m_alloc(sizeof(tmp0));tmp0->item=tmp; tmp0->item_size=sizeof(tmp); tmp0->next=NULL;	if (lista==NULL) { lista=tmp0; }else {	    		//aus=find_end(lista);		//aus->next=tmp0;	}	return;}