Why scanf asks for one more entry/value?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • minduser
    New Member
    • Sep 2009
    • 4

    #1

    Why scanf asks for one more entry/value?

    Here`s a simple program to convert time into seconds. For ex. 23:00:59-->82859.
    The problem is that the scanf always ask for a 4th value, which is not used in the conversion. Why? I`m using gcc.

    int convert(int hora, int minuto, int segundo){
    int i;

    i = hora*3600 + minuto*60 + segundo;
    return i;
    }

    int main(void){
    int h,m,s;
    scanf("%d\n", &h);
    scanf("%d\n", &m);
    scanf("%d\n", &s);

    printf("%d\n",c onvert(h,m,s));
    return 0;

    }
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Take out those "\n" characters from the scanf() calls.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      What do you mean "scanf always asks for a 4th value"?
      scanf doesn't display a prompt, so it isn't clear to me that it can ask for anything.

      Comment

      Working...