Hello

I've rearranged my program so i can enter more than one word for a field and it works,, new problem is after just entering data once,, i get stuck in the menu with a loop.

tried all kinds of stuff to get out but cant.

what i want to do is :
enter 1 to enter record
then after that it goes back to the menu and from there i want to press 1 again to enter the record again

neone know how i can do this???
apreciate any help,, Thanks

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

#define MAX 100
// Idea here is to enter an array of structures
// write them to disk and read them back


// simple structure
struct records {
	char artist[50];
	char album[50];
	char label[50];
	char year[4];
	char genre[30];
}cd[100];
	int top=0;
int filewrite(void) {
			
			int i;
			char years[4];
			char ch[2];
			for(i=top;i<1;i++)
			{
			
			printf("Press Y to Continue or N for Menu");
			gets(ch);
			printf("Enter the artist: \n");
			gets(cd[i].artist);
			printf("Enter the album: \n");
			gets(cd[i].album);
			printf("Enter label name: \n");
			gets(cd[i].label);
			printf("Enter year: \n");
			gets(cd[i].year);
			printf("Enter the genre of music: \n");
			gets(cd[i].genre);		
		}
			menu_select();
	
	top=i;
	}
	
	
	
	
	/*************************************************************/
void main(void)
{
  char c;
  
  c= menu_select();
  
  while(c!=5)
   
     switch(c)
	 {
	 case 1:
		  filewrite();
		  		break;
	 case 5:
		  		break;
	 	default:
		  		break;
	 }
	 }
   
   
   menu_select(void)
{  
char s[80];
int c;
     
     printf("GIVE CHOICE--\n");
     printf("   1 TO ENTER CD INFO.\n");
     printf("   2 TO SEE STUDENT.TXT FILE\n");
     printf("   3 TO SORT CDs BASED ON ARTIST\n");
     printf("   4 TO SEARCH USING ALBUM NAME\n");
     printf("   5 TO EXIT\n\n--");
   	
	do{
	printf("\nEnter Your Choice: ");
	 gets(s);
	 c = atoi(s);
		
			} while(c<0 || c>4);
				
				return c;
				}

Recommended Answers

All 2 Replies

try this

int top=0;
	
int filewrite(void) 
{
			
	int i;
	char years[4];
	char ch[2];
	for(i=top;i<1;i++)
	{
		printf("Press Y to Continue or N for Menu");
		gets(ch);
		printf("Enter the artist: \n");
		gets(cd[i].artist);
		printf("Enter the album: \n");
		gets(cd[i].album);
		printf("Enter label name: \n");
		gets(cd[i].label);
		printf("Enter year: \n");
		gets(cd[i].year);
		printf("Enter the genre of music: \n");
		gets(cd[i].genre);		
	}
	
	top=i;
}
	
	
	
	
	/*************************************************************/
void main(void)
{
  int c;
  
 
  while( ( c = menu_select() ) !=5)
   
	     switch(c)
		 {
		 case 1:
			  filewrite();
			  		break;
	 	default:
		  		break;
		 }
 }

nabil,

You forgot the braces for your while(C!=5) loop. That's where it goes into an infinite loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.