• 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 when you choose the first option it asks you how many contacts you wan to to add dont put a number there type a letter or a word and then you will see what i mean.

Link to comment
Share on other sites

  • 0

When you're calling scanf() to get the number of contacts, it'll return 1 if you enter a "valid" integer or 0 otherwise. Work off that to figure out if they entered a valid number or not.

Link to comment
Share on other sites

  • 0

yes i was thinking about that but thats the main problem suppose i write

if(contact == 1) ----------------------so the main thing is what shoudl i replace one with.

{

SHOW ME THE MENU

}

ELSE

so basical?ly saying how do i write this

if you enter a "valid" integer or 0 otherwise

Link to comment
Share on other sites

  • 0
int contacts = 0;
 int valid_int = 0;
 do
 {
   printf("how many contacts? ");
   valid_int = scanf("%d", &contacts);
 } while(valid_int == 0);

or something like that ^

Added to it slightly to make sure it doesn't endlessly loop if more than one character is input by the user :)

int main()
{
	int contacts = 0;
	int valid_int = 0;
	do
	{
		printf("how many contacts? ");
		valid_int = scanf("%d", &contacts);
		fflush(stdin);
	} while(valid_int == 0);

	printf("Contacts: %d\n", contacts);

	return 0;
}

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.