Thread: Reading data from a file and printing it

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Linux Trojan View Post
    Unfortunately, I havent programmed in C for a long while and I just dont understand the warning messages. Any suggestions?
    Yeah, start trying to understand the messages! Eg:

    foo.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 3 has type ‘int’

    You have a filename and a line number. So you know the problem is here:

    Code:
            fscanf(fp, "%s\n", a[i]);
    Hopefully what "format ‘%s’" refers to is obvious enough (WRT scanf/printf functions, the template is sometimes called a "format string"). And the third argument is not sympatico with this format.


    Deciphering compiler/interpreter errors and warnings can take practice. Remember, the primary objective of the compiler is to produce an executable; the messaging is secondary and may face limitations because of the primary objective. The messages are still useful clues, however. Always enable warnings and aim to compile without getting any.
    Last edited by MK27; 06-30-2011 at 12:18 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in a file and printing out a graph from the data
    By levitylek in forum C Programming
    Replies: 3
    Last Post: 10-26-2010, 07:32 PM
  2. Reading from file and printing double data
    By hammari in forum C Programming
    Replies: 4
    Last Post: 07-14-2009, 07:02 AM
  3. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 05:26 PM
  4. printing data to a file
    By coralreef in forum C Programming
    Replies: 3
    Last Post: 11-02-2006, 08:10 PM
  5. problems reading data into an array and printing output
    By serino78 in forum C Programming
    Replies: 4
    Last Post: 04-28-2003, 08:39 AM