Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Improve the following program so that the user can only enter positive numbers otherwise it will show that it is an error and let the

Improve the following program so that the user can only enter positive numbers otherwise it will show that it is an error and let the user try again. In addition to repeating several times the message to enter a number, until the user decides that he/she does not want to enter any more numbers.

#include

int main(){ FILE *archive; char c[100]; int number,n; int i; archive = fopen("archive.txt","a+t");//a i=1; if(archive==NULL){ printf(" Error opening the file"); exit(1); } //Request the user to enter positive S/Ns and write them to a file do{ printf("Enter a number: "); scanf("%i",number); fprintf(archive,"%d",number); }while(number>0); rewind(archive);

while(! feof(archive)){ fscanf(archive,"%d",&n); printf("%d",n); } fclose(archive); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions