To be honest bro, i really don't know the answer
Answer:
getc() or feof() in c/c++.
Explanation:
getc() returns EOF(End of File) when the end of the file reached is reached but it is not efficient because it also return EOF when it fails.
feof() returns non-zero value when the EOF is reached otherwise it return 0.So feof() is an efficient method to read a file.
For example:-
#include <stdio.h>
int main()
{
FILE *f = fopen("sample.txt", "r");
int c = getc(f);
while (c!= EOF)
{
putchar(ch);
ch = getc(f);
}
if (feof(f))
printf("\n File has ended.");
else
printf("\n Reading not happened.");
fclose(f);
getchar();
return 0;
}
In the program While loop is used. In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum. The inputs and corresponding outputs are written in the explanation.
<u>Explanation</u>:
In the while loop it divides the userNum by 2 in each iteration and prints the value of userNum.
import java.util.Scanner;
public class NonNegativeLooper
public static void main (String [] args)
Scanner scnr = new Scanner(System.in);
//initialize the userNum with 9
int userNum = 9;
//Repeat the loop until the userNum is not negative
while (userNum>=0)
System.out.println(Body);
//Prompt the user to enter the usrNum again
userNum = scnr.nextInt();
System.out.println(Done.);
return;