Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!