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

  • Thread starter Thread starter woofr_87
  • Start date Start date
  • Tags Tags
    Error Program
Click For Summary
SUMMARY

The program presented in the discussion is a C program designed to manage a library of books, but it contains a critical error in the function call to list the books. The original line list(library,count); is correct, while the suggested change list(library[count],count); leads to a runtime error due to incorrect pointer usage. The discussion highlights that the user is utilizing Microsoft Visual C++ 6.0 and is experiencing a runtime error when attempting to execute the program.

PREREQUISITES
  • Understanding of C programming language syntax and structures
  • Familiarity with function pointers and parameter passing in C
  • Knowledge of memory management and runtime errors in C
  • Experience with Microsoft Visual C++ 6.0 IDE
NEXT STEPS
  • Review C programming concepts related to function calls and parameter passing
  • Learn about debugging techniques in Microsoft Visual C++ 6.0
  • Explore memory management and common runtime errors in C
  • Study the use of structures in C and their manipulation
USEFUL FOR

Programmers, particularly those working with C, software developers debugging code, and students learning about data structures and memory management in C programming.

woofr_87
Messages
4
Reaction score
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
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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K