• 0

create a agenda in ansi c


Question

hey guys im learning ansi c and we got a homework to day to create a program which gets the name, address, email, phone number of a person and then we have to make a menu saying for e.g

1:-introduce the data(the name, address, email, phone number of a person)

2:-see the saved data

3:-compare the data

4:-find the data

5:-exit

we have to do this with funstions and structure.

so i was wondering any one has the program or can help me do this.

thanks you for reading.

Link to comment
Share on other sites

Recommended Posts

  • 0

Ok i wrote a tutorial on this through my phone but neowin kept telling me i was searching for a word with less than 2 keywords or "img" etc.

I changed to mobile skin and it lost post content :( i may re-post when I get home in 2 days.

Link to comment
Share on other sites

  • 0

We will help you yes but we're not just going to give you the answers. We're or at least I am not going to do it all for you.

Post the code of what you've done and what bits you don't understand :)

Link to comment
Share on other sites

  • 0

well again ill say just a heads up we(in class all the people) still havent seen the pointers yet and hdood please i mean comeone please a bit more then the libraries lol. thxs.

Edited by garryb
Link to comment
Share on other sites

  • 0

I shouldn't post this because you should do your class assignments on your own, but it's buggy and won't do all you ask so I hope you won't present this.

It will give you all the basic statements,functions and ideas you need, you can improve it and implement search etc.

#include <stdio.h>
#include <stdlib.h>


struct person{
		 char name[256];
		 int phone;
		 /* you can put any field you need here*/
		 };

void new_entry(FILE *data, struct person);
void read_data(FILE *data);		 

int main(int argc, char *argv[])
{

  struct person entry; /* we will use this to store the info on the memory before saving on file*/	   
  char answer; /*this var will be used to store the users option on the menu*/
  FILE *data;	   
  printf("Agenda in Ansi C\n");
  do
  {
	 printf("1. New Entry\n");
	 printf("2. Read data\n");
	 printf("3. Exit\n");
	 printf("Enter command : ");
	 answer = getchar();
	 if (answer == '1')
	 {
		new_entry(data,entry);
		getchar();
	 }
	 else if (answer == '2')
	 {
		read_data(data);
		getchar();
	 } 
  } while(answer != '3');  
  system("PAUSE");	
  return 0;
}

void new_entry(FILE *data,struct person entry)
{
	 data = fopen("c:\\dat.txt","a+"); /*a+ lets you read and write and appends the file if it exists*/
	 printf("Give the last name : ");
	 scanf("%s",&entry.name);
	 printf("Give the phone : ");
	 scanf("%d",&entry.phone);
	 fprintf(data,"%s %d\n",entry.name,entry.phone);
	 fclose(data);
}
void read_data(FILE *data)
{
	 int c;
	 data = fopen("c:\\dat.txt","r");
	 while ((c = fgetc(data)) != EOF) /*reads char by char from file*/
	 {
		   if (c == '\n') 
		   {
				 printf("\n");
		   }
		   else
		   {
			   putchar(c);
		   }
	 }	 
	 fclose(data);
}

Link to comment
Share on other sites

  • 0

You've been given the homework before you've been given any pointers in the class. I find it hard to believe the teacher would hand out homework if you hadn't already covered everything you need to know.

I shouldn't post this because you should do your class assignments on your own, but it's buggy and won't do all you ask so I hope you won't present this.

And yet you are...which is completely your choice of course. I just don't see the point of basically giving them the answer to their homework, it doesn't help them at all in the long run.

Link to comment
Share on other sites

  • 0

ok i agreee with you +vizion that this is not helping me in the long run but if u were in my shoes you would know ,i am a english speaking guy who currently am learning programming not in c++ but ansi c and in SPANISH which im not quiet fluent at, i joined this course which has programming , hardware, and networking because i was interested in hardware and networking but the worst part about this course is that if you dont pass one you have to repaet the full year.

and frankly speaking i jsut dont get programming , it is quiet hard and i know in the future im not going to be a progrrammer.

but hey i am serius we still havent done pointers or we call it here punteros so basically speaking the program which gianpan submitted above is no good to me because it seems like hes saving the data ina txt file which we havent covered in class so obivously my professor would be yaa rite u did it lol. anwyas ill post in one of my programs which we do in class so you can get a idead what ansi c im talking about. there you go one of my programs ok its in spanish.

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct empleado{
char nombre[10];
char DNI[10];
int edad;
} persona[10];
main()
{
int i, x;
float media;
float suma;
int menor;
printf("\nPrograma que recoge DNI y edad de 10 personas");
for(suma=0,i=0;i<10;i++)
{
printf("\nIngrese nombre de empleado %d: ",i+1);
gets(persona[i].nombre);
printf("\nIngrese DNI de empleado %d: ",i+1);
gets(persona[i].DNI);
printf("\nIngrese edad de empleado %d: ",i+1);
scanf("%d",&persona[i].edad);fflush(stdin);
system("cls");
suma=suma+persona[i].edad;
}
media=suma/10;
system("cls");
printf("\n\nLos empleados que tienen la edad mayor que la media son: ");
for(i=0;i<10;i++)
{
if(persona[i].edad>media)
{
printf("\n\nNombre: %s, DNI: %s, Edad: %d", persona[i].nombre, persona[i].DNI, persona[i].edad);
}
}
menor=persona[0].edad;
printf("\n\nEl empleado que es el menor de todos es: ");

for(i=0;i<10;i++)
{
if(persona[i].edad<menor)
{
menor=persona[i].edad;
x=i;
}
}
printf("\n\nNombre: %s, DNI: %s, Edad: %d",persona[x].nombre, persona[x].DNI, persona[x].edad);
getch();
}

Link to comment
Share on other sites

  • 0
ok i agreee with you +vizion that this is not helping me in the long run but if u were in my shoes you would know ,i am a english speaking guy who currently am learning programming not in c++ but ansi c and in SPANISH which im not quiet fluent at, i joined this course which has programming , hardware, and networking because i was interested in hardware and networking but the worst part about this course is that if you dont pass one you have to repaet the full year.

and frankly speaking i jsut dont get programming , it is quiet hard and i know in the future im not going to be a progrrammer.

but hey i am serius we still havent done pointers or we call it here punteros so basically speaking the program which gianpan submitted above is no good to me because it seems like hes saving the data ina txt file which we havent covered in class so obivously my professor would be yaa rite u did it lol. anwyas ill post in one of my programs which we do in class so you can get a idead what ansi c im talking about. there you go one of my programs ok its in spanish.

Learning a programming language is hard enough in your first language, nevermind a language you're not familiar with so I feel for you there. No offence, but I hope you write Spanish better than you write English ;)

Anyway, your code...gianpan's code is still usable, you just have to modify the code a bit. For point 2. See the saved data, do you have any more info on that? For saving the data I would do it the exact same way, output it to file and read it back in, so I'm not entirely sure what your teacher is expecting. It's the easiest way without having the input the data each time you open the program.

If the information does not require saving however, then you can just build on what you've already got in your code which is using arrays of structures. You then just need to keep track of how many users are stored, so you can display them correctly and know where to store the next user.

Link to comment
Share on other sites

  • 0
well as i todl you we still ahevnt done pointers here so thats why its of no use to me.

The only pointers I can see in gianpan's code is for writing to and reading from a file which as I said above, you don't need if you are not required to store the user details after the program has been closed. The rest of his code for inputting data looks OK, you just need to modify it a bit.

Link to comment
Share on other sites

  • 0
ok wht ill do is ill modify the code and add in some of my things as well and then post it then you and other people give me your take on it ok.

Sounds good :)

Link to comment
Share on other sites

  • 0
You've been given the homework before you've been given any pointers in the class. I find it hard to believe the teacher would hand out homework if you hadn't already covered everything you need to know.

And yet you are...which is completely your choice of course. I just don't see the point of basically giving them the answer to their homework, it doesn't help them at all in the long run.

It's his choice to study the code or not. It's just a basic i/o demo. If he wants a full/good mark out of this he must complete the app (search etc.) and make it more user friendly.

I don't like it when people give solutions which are not theirs but I can't make the choice for them.

I give you a bottle of water in the desert, drink it or wash your hands :)

Link to comment
Share on other sites

  • 0

okay people lets see i have finally done my program complie it and execute it and if you can help me find any bugs it will be of great help.

another thing is after my data is saved, i want to add another option of modifiying the introduced data for e.g i enter the name toni and his age 23

i would like to modify or change his age to 48 which i want to do inside the program.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct listado{
	   char nombre[15];
	   char apellidos[25];
	   int edad;
	   int phone;
	   char DNI[20];
	   char direcion[60];
	   };
void busqueda(struct listado agenda[],int cantidad);
void mostrar(struct listado agenda[],int cantidad);
main()
{
	  int i,contact,opcion;
	  struct listado agenda[20];
	  char sal;
	  do
	  {
			 system("cls");
			 printf("******AGENDA******");
			 printf("Menu Principal\n");
			 printf("1: Introducir los datos.\n");
			 printf("2: Buscar los datos.\n");
			 printf("3: Ver todos los contactos.\n");
			 printf("4: Salir.\n\n");
			 printf("Introdusca la opcion que desea realizar:");
			 scanf("%d",&opcion);
	  switch(opcion)
	  { 
	  case 1: 
	  system("cls");
	  printf(".\n");
	  printf("Cuantos contactos quieres introducir?:");
	  scanf("%d",&contact);
	  for(i=0;i<ca;i++){
						printf("Contacto # %d \n",i+1);
						printf("Introducir el Nombre:");	
						scanf("%s",&agenda[i].nombre);
						printf("Introducir  Apellidos:");	
						scanf("%s",&agenda[i].apellidos);
						printf("Introducir Edad:");   
						scanf("%d",&agenda[i].edad);fflush(stdin);
						printf("Introducir Telefono:");	
						scanf("%d",&agenda[i].phone);fflush(stdin);
						printf("Introducir DNI:");	
						scanf("%s",&agenda[i].DNI);
						printf("Introducir Direccion:");	
						scanf("%s",&agenda[i].direcion);
						system("cls");
						}
	  break; 
	  case 2:
	  busqueda(agenda,ca);
	  break;

	  case 3:
	  mostrar(agenda,ca);	
	  break;

	  case 4:
	  system("cls");
	  printf("Quieres salir?(S/N)");
	  sal=getch();
	  break;
	  }
	  }while(sal!='s');
	  getch();
	  system("cls");
	  printf("*************************Gracias por usar la agenda.****************************\n");
	  getch();
}
//Definicion de las funciones
void busqueda(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%s",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(strcmp(agenda[x].nombre, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s %s \nEdad:%d  \nTelefono:%d \nDNI: %s\nDireccion: %s \n",agenda[x].nombre,agenda[x].apellidos,agenda[x].edad,agenda[x].phone,agenda[x].DNI,agenda[x].direcion);	   
								 printf("***************************************************\n");
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s %s \nEdad:%d  \nTelefono:%d \nDNI: %s\nDireccion: %s \n",agenda[x].nombre,agenda[x].apellidos,agenda[x].edad,agenda[x].phone,agenda[x].DNI,agenda[x].direcion);	   
								 printf("***************************************************\n");
								 }
								 }
	if(k==0)
	{
			printf("La referencia no existe.");
			}							 
	getch();
	system("cls");
}	 
//Definicion de la 2da funcion
void mostrar(struct listado agenda[],int cantidad)
{
	 int i;  
	 system("cls");	   
	 printf("Los contactos almacenados son:\n");
	 for(i=0;i<cantidad;i++){
						   printf("Nombre:%s %s \nEdad:%d  \nTelefono:%d \nDNI:%s\nDireccion:%s \n",agenda[i].nombre,agenda[i].apellidos,agenda[i].edad,agenda[i].phone,agenda[i].DNI,agenda[i].direcion);	   
						   printf("***************************************************\n");
						   }
	 getch();
}

Link to comment
Share on other sites

  • 0
please somone help me i need to submit this project on monday.

It would probably help if you wrote some comments in english explaining what you are trying to do in the code. In addition, scanf is dangerous; for example if you type in more than 15 characters for nombre, it would result in a memory overflow. Corrupting the memory address space of your program and crashing it. It would be desirable to specify a field width and avoid this common mistake.

Edited by liberatus_sum
Link to comment
Share on other sites

  • 0

Sorry but I can't bug test your code, because although code is meant to be a universal language, I don't understand Spanish :p For your problem though. In order for you to modify data which you have already entered, you need some method of searching your array of structure.

One way might be to do something like this:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Person{
	char name[20];
	int age;
};

struct Person db[20];

int search(char *term);

int main()
{
	int pos = 0;

	strcpy(db[0].name,"Tony");
	db[0].age = 23;

	strcpy(db[1].name,"Colin");
	db[1].age = 48;

	pos = search("Colin");

	if(pos != -1){
		db[pos].age = 60;
		// Modify the stored data
		printf("Name: %s\n", db[pos].name);
		printf("Age: %d\n", db[pos].age);
	}

	return 0;
}

int search(char* term)
{
	int i = 0;

	for(i = 0; i < 20; i++){
		if(strcmp(db[i].name, term) == 0){
			return i;   // return the position within the array of structures
		}
	}

	return -1;  // Return -1 to show not found
}

The following code adds to people to to an array of structures, and then searches for a particular name to see if it exists. If it does it modifies the age and displays it on screen. Note the -1 return from search(). This is used so you know the search term was not found. Hope this helps

It would probably help if you wrote some comments in english explaining what you are trying to do in the code. In addition, scanf is dangerous; for example if you type in more than 15 characters for nombre, it would result in a memory overflow. Corrupting the memory address space of your program and crashing it. It would be desirable to specify a field width and avoid this common mistake.

You're right about scanf it is dangerous. Very similar to the use of gets, as its very easy to cause a buffer overflow and to write data where you shouldn't be. Just add a few defines at the top of the program to specify the maximum name length and then use fgets()

Link to comment
Share on other sites

  • 0

but hey is there any chance you can add this code which you posted again but merged with my original program o know im asking for a lot im kinda outta time.

Link to comment
Share on other sites

  • 0

ok guys please ignore my previous comment.

hey but if you guys can seriusly help me im looking for ADDING A WELCOME SCREEN TO MY PROGRAM LIKE THIS

61985015.th.jpg

so after this screen when i press enter my menu comes up and then at the end when the program exits i would also liek a goodbye or adios screen.

so i was wondering if someone can give me the code for it. thankyou.

Link to comment
Share on other sites

  • 0

You could make that manually if you really wanted to, although it seems like a lot of work for nothing.

i.e top line would be:

printf("##------##-####### etc" );
// repeat for each line

For the good bye screen you could just display a message before the program exits. Doing the same for the Welcome if enough also, rather than trying to implement the above.

Link to comment
Share on other sites

  • 0

	  printf(".\n");
	  printf("how many contacts do you want to add?:");
	  scanf("%f",&contacto);
	  for(i=0;i<contacto;i++){
						printf("El contacto numero %f es:\n",i+1);
						printf("Introducir el Nombre:");	
						scanf("%s",&agenda[i].nombre);
						printf("Introducir  Apellidos:");	
						scanf("%s",&agenda[i].apellidos);
						printf("Introducir Edad:");   
						scanf("%d",&agenda[i].edad);fflush(stdin);
						printf("Introducir Telefono:");	
						scanf("%d",&agenda[i].phone);fflush(stdin);
						printf("Introducir DNI:");	
						scanf("%s",&agenda[i].DNI);
						printf("Introducir Direccion:");	
						scanf("%s",&agenda[i].direcion);
						system("cls");
						}
						if(contacto == c)
						{
									printf("error");
									}

ok on the code above im getting an error when it asks how many contacts i want to add even if i type in a name it gets it and keeps on doing it ,

i want it to just get numbers. what should i do.

Link to comment
Share on other sites

  • 0

this is my ocde till now so please somone help me with the last error i posted.

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
struct listado{
	   char nombre[15];
	   char apellidos[25];
	   int edad;
	   int phone;
	   char DNI[20];
	   char direcion[60];
	   };
void busc(struct listado agenda[],int cantidad);
void mostrar(struct listado agenda[],int cantidad);
void busc1(struct listado agenda[],int cantidad);
void busc2(struct listado agenda[],int cantidad);
void busc3(struct listado agenda[],int cantidad);
void busc4(struct listado agenda[],int cantidad);
void busc5(struct listado agenda[],int cantidad);
void cambiar(struct listado agenda[],int cantidad);

main()
{
	  int i,contacto,opcion;
	  struct listado agenda[20];
	  char sal;
	  do
	  {
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");

		   printf("	######  ### ####### #	 # #	 # ####### #	 # ### ######  #######\n");
		   printf("	#	 #  #  #	   ##	# #	 # #	   ##	#  #  #	 # #	 # \n");
		   printf("	#	 #  #  #	   # #   # #	 # #	   # #   #  #  #	 # #	 # \n");
		   printf("	######   #  #####   #  #  # #	 # #####   #  #  #  #  #	 # #	 # \n");
		   printf("	#	 #  #  #	   #   # #  #   #  #	   #   # #  #  #	 # #	 # \n");
		   printf("	#	 #  #  #	   #	##   # #   #	   #	##  #  #	 # #	 # \n");
		   printf("	######  ### ####### #	 #	#	####### #	 # ### ######  ####### \n");	  
		   printf("\n														  Agenda de Garryb");
		   getchar();

			 system("cls");
			 printf("\n****AGENDA******\n");
			 printf("\n");
			 printf("Menu Principal\n");
			 printf("\n");
			 printf("1: Introducir los datos.\n");
			 printf("\n");
			 printf("2: Buscar por nombre.\n");
			 printf("\n");
			 printf("3: Buscar por apellido.\n");
			 printf("\n");			 
			 printf("4: Buscar por edad.\n");
			 printf("\n");			 
			 printf("5: Buscar por Telefono.\n");
			 printf("\n");			 
			 printf("6: Buscar por DNI.\n");
			 printf("\n");			 
			 printf("7: Buscar por Direccion.\n");			 
			 printf("\n");			 
			 printf("8: Ver todos los contactos.\n");
			 printf("\n");
			 printf("9: Salir.\n\n");
			 printf("---------------------------------------------------------------\n");
			 printf("\n");
			 printf("Introdusca la opcion que desea realizar:");
			 scanf("%d",&opcion);
	  switch(opcion)
	  { 
	  case 1: 
	  system("cls");
	  printf(".\n");
	  printf("Cuantos contactos quieres introducir?:");
	  scanf("%d",&contacto);
	  for(i=0;i<contacto;i++){
						printf("El contacto numero %d es:\n",i+1);
						printf("Introducir el Nombre:");	
						scanf("%s",&agenda[i].nombre);
						printf("Introducir  Apellidos:");	
						scanf("%s",&agenda[i].apellidos);
						printf("Introducir Edad:");   
						scanf("%d",&agenda[i].edad);fflush(stdin);
						printf("Introducir Telefono:");	
						scanf("%d",&agenda[i].phone);fflush(stdin);
						printf("Introducir DNI:");	
						scanf("%s",&agenda[i].DNI);
						printf("Introducir Direccion:");	
						scanf("%s",&agenda[i].direcion);
						system("cls");
						}
	  break; 
	  case 2:
	  busc(agenda,contacto);
	  break;

	  case 3:
	  busc1(agenda,contacto);
	  break;

	  case 4:
	  busc2(agenda,contacto);
	  break;

	  case 5:
	  busc3(agenda,contacto);
	  break;

	  case 6:
	  busc4(agenda,contacto);
	  break;

	  case 7:
	  busc5(agenda,contacto);
	  break;

	  case 8:
	  mostrar(agenda,contacto); 
	  break;								   

	  case 9:
	  system("cls");
	  printf("Quieres salir?(s/n)");
	  sal=getch();
	  break;
	  }
	  }while(sal!='s');
	  getch();
	  system("cls");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("\n");
		   printf("		 ######   ########	 ###	 ######  ####	###	 ######  \n");
		   printf("		##	##  ##	 ##   ## ##   ##	##  ##	## ##   ##	## \n");
		   printf("		##		##	 ##  ##   ##  ##		##   ##   ##  ##	   \n");
		   printf("		##   #### ########  ##	 ## ##		##  ##	 ##  ######  \n");
		   printf("		##	##  ##   ##   ######### ##		##  #########	   ## \n");
		   printf("		##	##  ##	##  ##	 ## ##	##  ##  ##	 ## ##	## \n");
		   printf("		 ######   ##	 ## ##	 ##  ######  #### ##	 ##  ######  \n");

	  getch();
}

void busc(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%s",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(strcmp(agenda[x].nombre, cade)== 0)
								 {
								 k++;
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);		 
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
}	 

void busc1(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%s",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(strcmp(agenda[x].apellidos, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	   
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	   
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
} 


void busc2(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 int cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%d",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(agenda[x].edad, cade== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	  
								 }
								 else if (agenda[x].DNI, cade== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);  
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
} 

void busc3(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%d",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if (agenda[x].phone, cade== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	   
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("DNI: %s\n",agenda[x].DNI);
								 printf("Direccion: %s\n",agenda[x].direcion);	
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
} 

void busc4(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%s",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("Direccion: %s\n",agenda[x].direcion);	   
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("Direccion: %s\n",agenda[x].direcion);	   
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
} 

void busc5(struct listado agenda[],int cantidad)
{
	 char opcion;
	 int x,t,k,d;
	 char cade[15];
	 system("cls");
	 printf("Introdusca la referencia de busqueda:");
	 scanf("%s",&cade);
	 system("cls");
	 for(k=0,x=0;x<cantidad;x++){
								 if(strcmp(agenda[x].direcion, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);		
								 }
								 else if (strcmp(agenda[x].DNI, cade)== 0)
								 {
								 k++;
								 printf("Nombre:%s",agenda[x].nombre);
								 printf("apellido:%s\n",agenda[x].apellidos);
								 printf("Edad:%d\n",agenda[x].edad);
								 printf("Telefono:%d\n",agenda[x].phone);
								 printf("DNI: %s\n",agenda[x].DNI);
								 }
								 }
	if(k==0)
	{
			printf("Introducirlo de nuevo.");
			}							 
	 system("pause");
	system("cls");
} 

void modificar(struct listado agenda[],int cantidad)
{
	 int conta,i;
	 printf("Estos son los contactos:\n");
	 for(i=0;i<cantidad;i++){
							 printf("#%d %s\n",i+1,agenda[i].nombre);
							 }
	 system("\n");
	 printf("Introdusca el # del contacto a modificar:");
	 scanf("%d",&conta);
	 printf("Ahora modifique el campo que desee.\n");
	 printf("Contacto # %d \n",i+1);
	 printf("Introdusca Nombre:");	
	 scanf("%s",&agenda[conta-1].nombre);
	 printf("Introdusca Apellidos:");	
	 scanf("%s",&agenda[conta-1].apellidos);
	 printf("Introdusca Edad:");	
	 scanf("%d",&agenda[conta-1].edad);fflush(stdin);
	 printf("Introdusca Telefono:");	
	 scanf("%d",&agenda[conta-1].phone);fflush(stdin);
	 printf("Introdusca DNI:");	
	 scanf("%s",&agenda[conta-1].DNI);
	 printf("Introdusca Direccion:");	
	 scanf("%s",&agenda[conta-1].direcion);
system("pause");
}




void mostrar(struct listado agenda[],int cantidad)
{
	 int i;  
	 system("cls");	   
	 printf("Los contactos almacenados son:\n");
	 for(i=0;i<cantidad;i++){
						   printf("Nombre:%s %s \nEdad:%d  \nTelefono:%d \nDNI:%s\nDireccion:%s \n",agenda[i].nombre,agenda[i].apellidos,agenda[i].edad,agenda[i].phone,agenda[i].DNI,agenda[i].direcion);	   
						   printf("***************************************************\n");
						   }
	 system("pause");
}

Link to comment
Share on other sites

  • 0

What did you say the problem was again? I tried it with one contact and I think it worked correctly. Even managed to display the contact using option 9 although I don't understand what any of it means :p

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.