Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program using text file I/O to open any file and print out all of the in

ID: 3638615 • Letter: W

Question

Write a program using text file I/O to open any file and print out all of the integers in the file, and their sum. You should input one character at a time, and convert contiguous characters into integers.

-Prompt for a name and open the file.
-Scan the file, and loop through each character, ignoring any character that is not a digit or a -sign.
   -If it is a - sign, store that information so the integer will be negative.
   -If it is a digit, set a currentInt value to the numeric value of that digit, and loop as long as there are    more digits, multiplying currentInt by 10 and adding the numeric value of the next digit.
-After the loop exits, multiply by -1 if it is negative, print it out and add it to a total.
Be careful that you don't try to read past the end of the file.

Explanation / Answer

#include #include int GetRand(int min, int max); int main(void) { int i, r, x; for (i = 0; i < 1001; i++) { r = GetRand(1, 1000); } while (1) { char last; printf("Pick a number between 1 and 1000 "); scanf("%d", &x); if (x r) { printf("Lower than %d ", x); } if (x == r) { printf("Correct! The correct number was %d! ", r); scanf("%c", &last); return 0; } } } int GetRand(int min, int max) { static int Init = 0; int rc; if (Init == 0) { srand(time(NULL)); Init = 1; } rc = (rand() % (max - min + 1) + min); return (rc); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote