In the first program you will enable the user to input ten inventory items. The
ID: 3555043 • Letter: I
Question
In the first program you will enable the user to input ten inventory items. The user will input the name of each item, the price of each individual item and how many of each item are in stock. You will accept the data inside a loop. The dialog with the user when requesting the input should be appropriate and comprehensive. The data will be stored in a file. The second program will output the contents of the file to the user's screen. The output will include appropriate labels for all of the data. You will output data using a loop. You will identify the file to be accessed using a graphic dialog box.
The two programs will be independent. By that, I mean that one program will not reference the other using objects or classes.
Explanation / Answer
#include<stdio.h>
void main()
{
FILE *fp1;
char *fname,ch[20];
clrscr();
printf(" enter source file name ");
gets(fname);
fp1=fopen(fname,"w");
if(fp1==NULL)
{
printf(" unable to open ");
exit(0);
}
printf(" enter the data:");
scanf("%s",ch);
fprintf(fp1,"%s",ch);
fflush(stdin);
printf(" data store in %s",fname);
fclose(fp1);
getch();
}
#include
int main(){
char str[70];
FILE *p;
if((p=fopen("string.txt","r"))==NULL){
printf(" Unable t open file string.txt");
exit(1);
}
while(fgets(str,70,p)!=NULL)
puts(str);
fclose(p);
return 0;
}
package com.java2novice.files;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class MyTempFileWrite {
public static void main(String a[]){
File tempFile = null;
BufferedWriter writer = null;
try {
tempFile = File.createTempFile("MyTempFile", ".tmp");
writer = new BufferedWriter(new FileWriter(tempFile));
writer.write("Writing data into temp file!!!");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try{
if(writer != null) writer.close();
}catch(Exception ex){}
}
System.out.println("Stored data in temporary file.");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.