What Is the Error in My Program and How Can I Fix It?

In summary, the conversation discusses a program with an error and the attempts to fix it. The program allows the user to add and list books in a library, but there is an error on line 43. The user tries to change the error and debug the code, but they encounter a run-time error. They are using Microsoft Visual C++ 6.0.
  • #1
woofr_87
4
0
hye everyone...this program have an error..


PHP:
#include<stdio.h>
#define MAX 10

struct book
{
	char title[81];
	char author[71];
	char category[31];
};


int main()
{
	struct book library[MAX];
	int menu(void);
	struct book add(void);
	void list (struct book, int);
	int choice,count = 0;

	do
	{
		choice = menu();
		switch(choice)
		{
		case 0 :
			puts("End of my act :-) ");
			break;

		case 1 :
			if(count < MAX)
			{

				library[count] = add();
				count++;
			}

			else
				puts("Library is reached maximum capacity");
			break;

		case 2 :
		list(library,count);
			break;

		default :
			puts("Wrong selection. Try again");
		}
	}while (choice != 0);
	return 0;
}


int menu(void)
{
	int choice;
	puts("\nSuper Duper Menu >>");
	puts("\t0: Exit");
	puts("\t1: Add a book");
	puts("\t2:List all books");
	scanf("%d",&choice);
	return choice;
}



struct book add(void)
{
	struct book temp;
	fflush (stdin);
	puts("\n<<ADD MORE>>");
	printf("Title?");
	gets(temp.title);
	printf("Author");
	gets(temp.author);
	printf("Category?");
	gets(temp.category);
	return temp;

}



void list (struct book * sp,int size)
{

	int i;
	printf("\n");
	puts("<<BOOK LIST>>");
	for(i=0;i<size; ++i, ++sp)
		printf("%d by %s --- %s\n",i+1,sp->title,sp->author,sp->category);
	return;
}


this program have an error at line 43..
i try to change the error to be like this :

PHP:
	list(library[count],count);

Am i right??

but..when i want to debug this code, the compiler said that this code don't have an error..and then, when i want to run this code, the compiler said this code have an error..
opss...im using Microsoft Visual C++ 6.0..
 
Physics news on Phys.org
  • #2
Sounds like you're gettin a run-time error, not a compiler error. If you are running your program, the compiler has already generated the executable.

What's the error you are getting, and what operation are you perfoming when you get the error?
 

Related to What Is the Error in My Program and How Can I Fix It?

1. What are some common types of errors in programming?

Some common types of errors in programming include syntax errors, logical errors, and runtime errors.

2. How can I find and fix errors in my program?

The best way to find and fix errors in your program is to use a debugger or step through your code line by line to identify where the error is occurring. Additionally, using logging and error messages can help pinpoint the issue.

3. What should I do if I encounter an error I don't understand?

If you encounter an error that you don't understand, try to research the error message or consult with other programmers for help. It can also be helpful to break down your code and try to identify the specific line or function causing the error.

4. How can I prevent errors in my program?

To prevent errors in your program, it's important to thoroughly test your code and use good coding practices such as commenting, using proper indentation, and following best practices for the language you are using. It's also helpful to have someone else review your code for errors.

5. What should I do if I can't fix an error in my program?

If you are unable to fix an error in your program, it may be helpful to seek assistance from other programmers or take a break and come back to it with a fresh perspective. Sometimes, taking a step back can help identify the issue more easily.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
878
  • Engineering and Comp Sci Homework Help
Replies
5
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top