Thread: Super Newb question

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    2

    Super Newb question

    Hi guys,

    I'm just starting into the world of C. As an exercise to help reiterate what I've learned I'm trying to make a madlib, for fun.

    I'm running into issues trying to have the user input 2 variables of the same type.

    For example, this works:


    Code:
                      switch (answer) {
                             case 'Y':
                             case 'y':
                                  printf("I'm so glad you want to play through my madlib!\n");
                                  printf("First we'll need a Proper Noun: ");
                                  scanf("%25s", propnoun);
                                  printf("Now we need a Number: ");
                                  scanf("%25d", &num1);
                                  printf("testing %s, and %d.\n", propnoun, num1);
                                  getchar ();
                                  getchar ();
                                  break;
    But this gives a compile error of:
    'Linker error' undefined reference to `Printf'

    Code:
                      switch (answer) {
                             case 'Y':
                             case 'y':
                                  printf("I'm so glad you want to play through my madlib!\n");
                                  printf("First we'll need a Proper Noun: ");
                                  scanf("%25s", propnoun);
                                  printf("Now we need a Number: ");
                                  scanf("%25d", &num1);
                                  Printf("Sweet, give us another Number: ");
                                  scanf("%23d", &num2);
                                  printf("testing %s, %d, and %d.\n", propnoun, num1, num2);
                                  getchar ();
                                  getchar ();
                                  break;
    I'm sure I'm missing something very simple, a little guidance would be very appreciated.

    Thanks in advance

    Damien

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    12
    Hi,

    you have used a uppercase letter(pointed by orange color) in printf statement, that's why you are getting an linker error


    Code:
    switch (answer) {
                             case 'Y':
                             case 'y':
                                  printf("I'm so glad you want to play through my madlib!\n");
                                  printf("First we'll need a Proper Noun: ");
                                  scanf("%25s", propnoun);
                                  printf("Now we need a Number: ");
                                  scanf("%25d", &num1);
                                  Printf("Sweet, give us another Number: ");
                                  scanf("%23d", &num2);
                                  printf("testing %s, %d, and %d.\n", propnoun, num1, num2);
                                  getchar ();
                                  getchar ();
                                  break;

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    C is case sensitive - P is different from p.

    Another thing - instead of using two getchar()s, try this:
    Code:
    int c;
    while((c = getchar()) != '\n' && c != EOF);
    getchar();
    My code will work if the user enters something like 123b, and yours won't.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    2

    Thanks

    I knew it would be something simple that Iw as missing, I didn't realize the case sensativity, thanks to both of you.

    I changed the case in my printf, and the restof the madlib has worked so far.

    And I'll be trying out that while loop as well,

    Thanks again!

    Damien

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question Character Counting
    By Wilder in forum C Programming
    Replies: 13
    Last Post: 06-22-2008, 11:37 PM
  2. newb error question
    By diablo_mabbs in forum C Programming
    Replies: 7
    Last Post: 06-17-2008, 01:36 AM
  3. super noob question
    By verbity in forum C++ Programming
    Replies: 6
    Last Post: 06-23-2007, 11:38 AM
  4. newb question
    By Jan79 in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2003, 09:59 AM
  5. Win app, newb question
    By Blender in forum Windows Programming
    Replies: 9
    Last Post: 02-04-2003, 12:17 PM