C Programming Help !

Sudantha_s

Member
Feb 2, 2007
3,516
7
0
Assassin Brotherhood
Im entering data to a Strcure in C program :) .. but da data overight in same location :( .. pls help !


Code:
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>

#define MAX 5

	//contact strcutre
	typedef struct contact
	{
	  char first[25];
	  char last[25];
	  double num[10];

	};


	contact c[5];
   contact arr[MAX];

//function define
void add_new();
void edit();
void menu();
void view();
void search();

// ***BEGIN OF ADD CONTACT***
void add_new()
{

 up:
 char input1;
 //contact c[5];
 clrscr();
 for(int i=0;i<MAX;i++)
 {
		printf("\n\n\tAdd a new contact\n");
		printf("\n Enter the First  Name :");
		fflush(stdin);
		gets(c[i].first);
		printf("\nEnter Surname :");
		gets(c[i].last);
		fflush(stdin);
		printf("\n Enter the Number :");
		scanf("%d",&c[i].num);
		fflush(stdin);
		clrscr();
		printf("\nName  :  %s%s%s",c[i].first," ",c[i].last);
		printf("\nNumber : %s",c[i].num);
		//menu:
		printf("\n\n\tDo you Want to Add More Contacts (Y/N) : ");
		scanf("%s",&input1);
 //scan user value
		fflush(stdin);
 if(input1=='y')
	{
	  clrscr();
	  printf("\n\n\tData Saved !");
	  goto up;
	}

 else if (input1=='n')
	{
		clrscr();
		menu();

	}
 else
	{
	clrscr();
	printf("\n\tInvalid Input!");
  //	goto menu;
	}


	}


}

//***END OF ADD FUNCTION***

//***BEGIN SHOW ALL CONTACTS FUNCTION
void view()
{



for(int j=0;j<MAX;j++)
	{
		 //view contacts
		 printf("\n Name : %s%s%s",c[j].first," ",c[j].last);
		 printf("\n Number %s\n",c[j].num);
	}


}
//*** END OF ADD FUNCTION

//**BEGIN SEARCH FUNCTION**
void search(void)
{

char name_s[25];
int i;


clrscr();
printf("\n\n\t Search a Contact");

printf("\n\nEnter a Name to Search : ");
gets(name_s);
fflush(stdin);

for(i=0;i<5;i++)
		{
			if (strcmp(c[i].first,name_s))
				{
					 printf("Found !");
					break;
				}
			else
				{
					printf("Not FOund !");
					break;

				}
		}




}




//**END OF SEARCH FUNCTION






//main
void main()
{

	contact c[5];

	menu();



}


//menu fuction
void menu()
{

	int input;
	menu:
	printf("\n\t[1] Create My Phone Book\n");
	printf("\n\t[2] Modify Contact\n");
	printf("\n\t[3] Display All Records\n");
	printf("\n\t[4] Search a Number\n");
	printf("\n\t[5] Exit\n");

	//user select option
	printf("\n\n Enter the Choice : ");
	scanf("%d",&input);
	fflush(stdin);

	if (input==1)
		{
		//load add
		add_new();

		}

  else if (input==2)
		{
		//modfy
		}
  else if (input==3)
		{
		 clrscr();
		 view();
		}
  else if (input==4)
		{
		  //search
		  search();

		}
  else if(input==5)
		{
		  abort();
		}

  else
	 {
		 printf("Invalid Error !");
		 menu;
	 }


}