Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct Books {
- char* id;
- char* title;
- char* pages;
- char* year;
- char* author;
- char* subject;
- } book;
- char* filename;
- int bookcount=4;
- int main(int argc, char* argv[]){
- if (argc < 1)
- return -1;
- filename=argv[1];
- char* sptr;//pointer for text size
- char* lptr;//to point the size of the library
- char tempstring[1024],*token;
- int i=0;
- lptr=(char*) malloc(bookcount*sizeof(book));
- *lptr=bookcount;
- book books[*lptr];
- FILE *fptr;
- fptr=fopen(filename,"r");
- if(fptr==NULL)
- return-1;
- for(i=0;i<bookcount;++i){ //suppose to get all the books into the book array
- fgets(tempstring,1024,fptr);
- token = strtok(tempstring, ",\n");
- strcpy(books[i].id,token);
- token = strtok(NULL, ",\n");
- strcpy(books[i].title,token);
- token = strtok(NULL, ",\n");
- strcpy(books[i].pages,token);
- token = strtok(NULL, ",\n");
- strcpy(books[i].year,token);
- token = strtok(NULL, ",\n");
- strcpy(books[i].author,token);
- token = strtok(NULL, ",\n");
- strcpy(books[i].subject,token);
- token = strtok(NULL, ",\n");
- }
- fclose(fptr);
- printf("%s",books[i].id);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement