Thread: I need help figuring out this code for my homework. I don't understantd the EOF part

  1. #1
    Registered User
    Join Date
    Aug 2019
    Posts
    2

    Post I need help figuring out this code for my homework. I don't understantd the EOF part

    insert
    Code:
    #include <stdio.h>
    
    
    int main() {
        int a, b, c;
        
        printf("Enter integer a:");
        scanf("%d", &a);
        if(a>0){
            
            printf("Enter integer b:");
            scanf("%d", &b);
            if(b>=a){
                printf("End of program number greater than or equal to a");
            }
            {
            
              while((c= getchar()) != EOF) a++;
            
               printf("Succesful = %d\n", a );
            
            }
        }
    
    
        return 0;
    }
    Attached Images Attached Images

  2. #2
    Registered User
    Join Date
    Aug 2019
    Posts
    2
    The homework question is in the attatchment

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well for a start, nowhere in your assignment does it say to use getchar().

    Perhaps you can start with that.

    The bit about scanf and EOF means you should be doing something like
    Code:
    while ( scanf("%d",&myint) != EOF ) {
      // do something
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    null pointer Structure's Avatar
    Join Date
    May 2019
    Posts
    338
    I don't understand the eof part.


    End-of-file - Wikipedia


    While ( !eof ) { }

    While Not End Of File
    "without goto we would be wtf'd"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-22-2012, 10:41 AM
  2. figuring out code
    By Thegame16 in forum C Programming
    Replies: 16
    Last Post: 09-23-2011, 06:47 PM
  3. cant see what certain part of this code does..
    By transgalactic2 in forum C Programming
    Replies: 4
    Last Post: 04-14-2009, 06:22 AM
  4. Can someone look over my code? part 2
    By brooklyn in forum C++ Programming
    Replies: 10
    Last Post: 04-18-2006, 06:33 AM

Tags for this Thread