Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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

GeneralRe: Help compiling a library program in 'C' Pin
warpbro4-Jun-09 22:22
warpbro4-Jun-09 22:22 
QuestionHow to trace/log 3rd Party library API calls made by an application through WinDbg [modified] Pin
ComplexLifeForm2-Jun-09 8:51
ComplexLifeForm2-Jun-09 8:51 
Questioncalculte time between two dates !!! Pin
pillsforkills2-Jun-09 6:23
pillsforkills2-Jun-09 6:23 
QuestionRe: calculte time between two dates !!! Pin
CPallini2-Jun-09 6:36
mveCPallini2-Jun-09 6:36 
QuestionRe: calculte time between two dates !!! Pin
David Crow2-Jun-09 7:48
David Crow2-Jun-09 7:48 
Questionsha256 test vector Pin
Bill Salibrici2-Jun-09 5:52
Bill Salibrici2-Jun-09 5:52 
QuestionControl CStatic, Height of FONT Pin
durban22-Jun-09 4:28
durban22-Jun-09 4:28 
AnswerRe: Control CStatic, Height of FONT Pin
Hamid_RT2-Jun-09 5:17
Hamid_RT2-Jun-09 5:17 
AnswerRe: Control CStatic, Height of FONT Pin
nyeboy2-Jun-09 6:55
nyeboy2-Jun-09 6:55 
GeneralRe: Control CStatic, Height of FONT Pin
ForNow1-Jul-15 8:08
ForNow1-Jul-15 8:08 
Questionfunction Pin
durban22-Jun-09 4:07
durban22-Jun-09 4:07 
AnswerRe: function Pin
Chris Losinger2-Jun-09 4:10
professionalChris Losinger2-Jun-09 4:10 
NewsRe: function Pin
CPallini2-Jun-09 6:29
mveCPallini2-Jun-09 6:29 
QuestionUrgent please from Ethiopia! Pin
mekonnenn2-Jun-09 3:51
mekonnenn2-Jun-09 3:51 
AnswerRe: Urgent please from Ethiopia! Pin
CPallini2-Jun-09 4:00
mveCPallini2-Jun-09 4:00 
AnswerRe: Urgent please from Ethiopia! Pin
David Crow2-Jun-09 4:22
David Crow2-Jun-09 4:22 
JokeRe: Urgent please from Ethiopia! Pin
Hamid_RT2-Jun-09 5:20
Hamid_RT2-Jun-09 5:20 

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.