Thread: Code issue scanf() string line 28

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2020
    Posts
    6

    Code issue scanf() string line 28

    Hi,

    I'm developing a very small project, and while implementing it I got some issue. I already did this kind of exercises a few times, but I don't seem to understand what is wrong (the scanf to get string/char array input. A compiler error related to the type of variable and or number of arguments.)
    I'm using code blocks and windows10 at this moment.

    This is still a code in progress, and as a newbie I will also appreciate best practice's tips.

    Code:
    #include <stdio.h>#include <stdlib.h>
    
    
    #define MAXINPUT 20 //use this value to max loop (apply later)
    
    
    struct Book // Structure type definition
    {
     char title [10];
     int pages;
    
    
    }books[10];
    
    
    int main()
    {
        int i = 0;
        int option;
    
    
        while (i < 10)
        {
        printf("Do you want to enter details of BOOK 1 (yes) or 0 (No)? ");
        scanf("%d", &option);
    
            if (option == 1)
            {
                printf("\n Title name: ");
                scanf("%s", &books[i].title);
    
    
                printf("\n Number of pages: ");
                scanf("%d \n", &books[i].pages);
    
    
            }
            else if (option == 0)
            {
                printf("It was not yes \n");
                break;
    
    
            }
            else{
    
    
                printf("Valid input, go back to main menu \n");
                break;
    
    
            }
            i++;
    
    
        }
    
         // save records to file// to be written
    
        //display records created
    
    
        for (i = 0; i < 2; i++) {
    
    
           printf("Book title: ");
           puts(books[i].title);
           printf("Page number:  %d", books[i].pages);
           printf("\n");
        }
    
    
        //display all saved record//to be written
    
    
    
    
    
    
        return 0;
    }
    warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10]' [-Wformat=]
    Last edited by JazzDev; 01-28-2020 at 04:29 AM. Reason: its no longer line 28

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf issue
    By cooper1200 in forum C Programming
    Replies: 16
    Last Post: 04-16-2019, 04:18 AM
  2. Multiple printf/scanf code issue
    By kumczak in forum C Programming
    Replies: 2
    Last Post: 04-08-2014, 08:33 AM
  3. N00b @ C: Code is failing at line 12 which is a basic scanf
    By Mike Garber in forum C Programming
    Replies: 3
    Last Post: 09-01-2013, 10:25 AM
  4. 'cin' and 'scanf()' issue
    By Brain Cell in forum C++ Programming
    Replies: 4
    Last Post: 11-07-2004, 10:53 AM
  5. scanf issue
    By fkheng in forum C Programming
    Replies: 6
    Last Post: 06-20-2003, 07:28 AM

Tags for this Thread