Hi.
How can I assign an structure with values in its fields name=doom
memory=1212, time=12, files=2; but dinamically???
so i use malloc sixe of
the list does not begin in NULL instead "doom"
i have a menu that insert a new Node, when you press F1
printinscreen when you press F2,
SO WHEN I PRESS F2 I WANT THAT THE PROGRAM SHOWS
DOOM
1212
12
2
HOW CAN I DO IT???????????????????????????????
I KNOW THAT the structure has the fields:
struct proceso{
char name[20];
char memory[10];
char time[10];
char files[10];
};
and I HAVE TO USE
strcpy( ????->name = Doom3;
strcpy( ?¡???->memory=1212;
strcpy( ?????->time=14;
strcpy( ????->files=2;
BUT HOW?
PLEASE HELP ME, WHEN I PRESS F2 I WANT TO SHOW
DOOM AND OTHER FILEDS, SO THE LIST FIRST ELEMENT OF THE LIST IS DOOM, NOT NULL
I have done this:
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define F1 59
#define F2 60
#define ESC 27
struct proceso{
char name[20];
char memory[10];
char time[10];
char files[10];
};
struct Node{
struct proceso info;
struct Nodo *next;
};
/////////////////////////////////////////////////////////////////////////
///////////////////////Create a Node////////////////////////////////////
struct Nodo *createnodo(struct proceso data)
{
struct Nodo *aux;
aux=(struct Nodo *)malloc(sizeof(struct Nodo));
strcpy(aux->info.name,data.nombre);
strcpy(aux->info.memory,data.memory);
strcpy(aux->info.time,data.time);
strcpy(aux->info.files,data.files);
return(aux);
}
////////////////////////////////////////////////////////////////
/////////////////////Funcion print in screen//////////////////////////
void printinscreen(struct Nodo *Lista)
{
struct Nodo *aux;
aux=Lista;
while(aux!=NULL)
{
printf("\n\n%s", aux->info.name);
printf("\n%s", aux->info.memory);
printf("\n%s", aux->info.time);
printf("\n%s", aux->info.files);
aux=aux->sig;
}
}
///////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
int menu()
{
char opc;
clrscr();
printf("\n\n **== MENU ==** \n\n\n");
printf(" <<F1>> Insert \n");
printf(" <<F2>> Print in screen \n");
printf(" <<ESC>> exit \n\n");
opc=getch();
if ((int) opc==0)
opc=getch();
return ((int)opc);
}
///////////////////////////////////////////////////////
void main()
{
struct Nodo *Lista=NULL;/////here that *Lista= proceso1????///
struct proceso data;
int pos;
int accion=0;
while (accion!=ESC)
{
accion=menu();
clrscr();
switch(accion)
{
case F1:/* printf("\nUsted selecciono Inserta\n\n");
printf("\Give:\n");
printf("\nName: ");
scanf("%s", &data.name);
printf("\nMemory: ");
scanf("%s", &data.memory);
printf("\nTime: ");
scanf("%s", &data.time);
printf("\nNumber of files: ");
scanf("%s", &data.files);
scanf("%d", &pos);
inserta(&Lista, data, pos);
printf("\nSaved!!! \n");
break;
case F2: printf("\n\n Print in Screen\n");
printinscrren(Lista);
break;
case ESC: printf("\n Press a button to exit... \n");
getch();
break;
default: printf(" \n\n\n !!! Error \n\n");
getch();
}
getch();
}
}