Thread: Scanf value trouble

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    1

    Scanf value trouble

    Hey, as part of a function for a homework assignment I need to check whether scanf reached EOF.
    the code line goes like this :
    Code:
    res=scanf(" %lf",&array[i][j]);
                if (res==EOF)
                {
                    return i;
                }
                 printf("cell is %d\n",array[i][j])
    for some reason the array wont recieve any value from "scanf" , and when I check its values with printf it will stay all zeros

    am I doing something wrong ?

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    647
    From scanf() manpage:

    RETURN VALUE
    On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure.

    The value EOF is returned if the end of input is reached before either the first successful conversion or a matching failure occurs. EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set to indicate the error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple programme trouble printf and scanf
    By rispodium in forum C Programming
    Replies: 8
    Last Post: 12-03-2013, 02:23 PM
  2. Trouble with scanning 2 strings in same scanf call
    By Brolaf Broski in forum C Programming
    Replies: 3
    Last Post: 11-20-2013, 05:39 PM
  3. trouble with scanf and validating input
    By fazio93 in forum C Programming
    Replies: 14
    Last Post: 05-23-2013, 03:43 PM
  4. scanf trouble
    By sloke in forum C++ Programming
    Replies: 4
    Last Post: 11-16-2005, 03:31 PM
  5. Having trouble with scanf function
    By cw3od in forum C Programming
    Replies: 2
    Last Post: 11-28-2001, 03:58 PM

Tags for this Thread