Thread: stupid scanf question

  1. #1

    Angry stupid scanf question

    Please have patience with me on this. I just started reading a book about C and it instructed me to type the following:

    #include <stdio.h>

    void main()
    char txt[80];
    printf("Enter data:");

    When compiling (gcc) I got 2 messages:
    lots of dirs and then about file crt1.o it said "in function '_start':"
    and the second line same dirs and about file crt01.a(.txt+0x18)and then the message "undefined reference to main"

    as it talks about txt i changed the declaration to 20 (i thought perhaps the line is too long, but the same message keeps apearing.

    There is probably a very easy explanation but I just dont know enough yet to find it myself. Anyone please?

  2. #2
    dooooh! please forget that question, used man instead of main
    O well, it gets me getting better in reading & understanding the messages the compiler gives.

  3. #3
    >void main()
    That line right there should tell you to return that book and get another one. I don't see why so many authors still use void main, it's not standard and therefore declared as 'undefined' by ISO C.

    void main is wrong, period. And if the author uses void main then chances are good he/she made other big mistakes as well. Speaking of other mistakes...

    > printf(txt);
    Prints out an array, makes sense in that little code but what if the hapless reader uses it in a 10000 line program? How am I supposed to know what txt is? The name alone 'should' tell me what it does, but never assume that the name will convey the correct info; that statement should have been written like this:
    printf("%s", txt);
    Print out a string with an array as the argument, it has to be an array because there would be errors if you used %s with any other data type. Now the reader knows what's going on.

    Since it's the beginning of the book I'll refrain from bashing scanf, it's simple and that's a good enough excuse for now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Question Regarding Scanf() & Phone Numbers!
    By weaveram in forum C Programming
    Replies: 3
    Last Post: 09-20-2007, 09:58 AM
  2. Question on scanf();
    By Utopus in forum C Programming
    Replies: 4
    Last Post: 06-15-2007, 07:46 AM
  3. Replies: 7
    Last Post: 11-04-2005, 12:17 AM
  4. Stupid Question
    By digdug4life in forum C++ Programming
    Replies: 22
    Last Post: 05-17-2005, 11:43 AM
  5. stupid, stupid question
    By xelitex in forum C++ Programming
    Replies: 5
    Last Post: 12-22-2004, 08:22 PM