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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started