Click here to Skip to main content
15,922,584 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How to design a decoder in C++? Pin
CPallini2-Jun-09 21:22
mveCPallini2-Jun-09 21:22 
AnswerRe: How to design a decoder in C++? Pin
Stuart Dootson2-Jun-09 22:55
professionalStuart Dootson2-Jun-09 22:55 
GeneralRe: How to design a decoder in C++? Pin
kapardhi3-Jun-09 18:35
kapardhi3-Jun-09 18:35 
GeneralRe: How to design a decoder in C++? Pin
Stuart Dootson3-Jun-09 21:33
professionalStuart Dootson3-Jun-09 21:33 
GeneralRe: How to design a decoder in C++? Pin
kapardhi4-Jun-09 3:27
kapardhi4-Jun-09 3:27 
GeneralRe: How to design a decoder in C++? Pin
Stuart Dootson4-Jun-09 3:31
professionalStuart Dootson4-Jun-09 3:31 
GeneralRe: How to design a decoder in C++? [modified] Pin
kapardhi4-Jun-09 3:49
kapardhi4-Jun-09 3:49 
GeneralRe: How to design a decoder in C++? Pin
Stuart Dootson4-Jun-09 3:59
professionalStuart Dootson4-Jun-09 3:59 
GeneralRe: How to design a decoder in C++? Pin
kapardhi4-Jun-09 21:03
kapardhi4-Jun-09 21:03 
GeneralRe: How to design a decoder in C++? Pin
Stuart Dootson4-Jun-09 21:45
professionalStuart Dootson4-Jun-09 21:45 
GeneralRe: How to design a decoder in C++? Pin
kapardhi5-Jun-09 0:05
kapardhi5-Jun-09 0:05 
GeneralRe: How to design a decoder in C++? Pin
Stuart Dootson5-Jun-09 0:23
professionalStuart Dootson5-Jun-09 0:23 
QuestionUrgent! Smart house with SMS project Pin
ericyeoh2-Jun-09 16:33
ericyeoh2-Jun-09 16:33 
QuestionRe: Urgent! Smart house with SMS project Pin
CPallini2-Jun-09 21:39
mveCPallini2-Jun-09 21:39 
QuestionMFC Process Pin
duongcntt4b2-Jun-09 15:39
duongcntt4b2-Jun-09 15:39 
QuestionRe: MFC Process Pin
David Crow2-Jun-09 16:52
David Crow2-Jun-09 16:52 
AnswerRe: MFC Process Pin
Stephen Hewitt2-Jun-09 20:34
Stephen Hewitt2-Jun-09 20:34 
AnswerRe: MFC Process Pin
duongcntt4b2-Jun-09 21:26
duongcntt4b2-Jun-09 21:26 
GeneralRe: MFC Process Pin
David Crow3-Jun-09 2:34
David Crow3-Jun-09 2:34 
QuestionC and C++ malloc and free Pin
jobin0070072-Jun-09 11:59
jobin0070072-Jun-09 11:59 
AnswerRe: C and C++ malloc and free Pin
John R. Shaw2-Jun-09 13:40
John R. Shaw2-Jun-09 13:40 
QuestionHelp compiling a library program in 'C' [modified] Pin
warpbro2-Jun-09 11:11
warpbro2-Jun-09 11:11 
QuestionRe: Help compiling a library program in 'C' Pin
David Crow2-Jun-09 16:54
David Crow2-Jun-09 16:54 
AnswerRe: Help compiling a library program in 'C' Pin
norish2-Jun-09 17:51
norish2-Jun-09 17:51 
GeneralRe: Help compiling a library program in 'C' [modified] Pin
warpbro3-Jun-09 4:13
warpbro3-Jun-09 4:13 
It's to be a console application done in C. Some problems with what I have so far are; when search results are found it must only show the result once, if only one book has been entered to the file, the search kicks out the result 8 times because of the loop any suggestions? I' ve been using other similar source code to try and get a working program but I keep hitting errors. How can I get the program to handle spaces between words, eg; 'The book of games'
Here's what I've got so far,

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

int main(int argc, char *argv[])
{
  // Declaring the varibles within structure     
      int choice,isbn,title,author;
    
      typedef struct  
    {
           char author [15];
           char title [30];
           char  isbn [15];
           
    }
// Naming the structure
    library;  
// Declaring Binary File   
    FILE *lbooks;
// Do While Loop (will return to main screen after input)
while (choice != 5)
{
library books;

// Main Screen Choices
printf ("\n\n\t\t\t\tForth Valley Training\n\n\n");
printf ("\t\t1.   Add a new book.\n\n");
printf ("\t\t2.   Search for book by ISBN\n\n");
printf ("\t\t3.   Search for book by Title\n\n");
printf ("\t\t4.   Display Details of Books Held\n\n");
printf ("\t\t5.   Exit\n\n\n");
printf ("\t\tPlease enter your choice..");
scanf ("%i", &choice);    
// Switch statement to carry out users choice from the menu 
switch (choice) {
       case 1 : system("cls");
       
// Open binary file for amending       
       lbooks = fopen("BookFile.bin","ab");
// Prompts for and reads in new book details       
printf ("Please enter ISBN..\n");
scanf ("%s", &books.isbn);
printf ("Please enter Author..\n");
scanf ("%s", &books.author);
printf ("Please enter Title..\n");
scanf ("%s", &books.title);
fwrite(&books,sizeof(books),1,lbooks);
fclose(lbooks);
       break; 
       case 2 : system("cls");
// Declare integer for isbn search number        
      int  srch1 [15],loop;

loop == '0';      
printf ("Please enter ISBN number..");
scanf ("%s", &srch1);
// Using FOR LOOP against each record entry; IF TRUE THEN display record books 
// Fseek will loop eigth times for a maximum entry of eigth books
for(loop = 0;loop <=8;loop++)  
{ 
lbooks =fopen("BookFile.bin","r+");   
fseek(lbooks,sizeof(books)*loop,SEEK_SET);    
fread(&books,sizeof(books),1,lbooks); 
if (srch1 == library.isbn)
printf ("\n%10i %10s %20s\n\n", books.isbn,books.author,books.title);
fclose(books);     
} 
       system("PAUSE");	
       break;       
       case 3 : system("cls");
  int result;
  char srch2[25];
loop == '0';
printf ("Please enter book Title..");
scanf ("%s", &srch2);
for(loop = 0;loop <=8;loop++)  
{   
books =fopen("BookFile.bin","r+");   
fseek(books,sizeof(books)*loop,SEEK_SET);    
fread(&books,sizeof(books),1,books); 
result = (strcmp(srch2, books.title));
if (result == 0)
{
printf ("\n%15s %15s %12i\n\n", books.title,books.author,books.isbn);
fclose(books);
}    }
system("pause");
     break;
     case 4 : system("cls"); 
              books = fopen("BookFile.bin","rb");
         while (!feof(books))
{  
       fread(&books, sizeof(books),1,books);
  if (!feof(books))
       printf (" %10i %10s %20s\n", 
            books.isbn,books.author,books.title);
}
  fclose(books
  );
       system("PAUSE"); 
       break;

       }      
       fclose(books);
       system("cls");
       }
       


  system("PAUSE");	
  return 0;
}



Thanks for looking at this program warpbro

modified on Thursday, June 4, 2009 9:11 AM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.