0% found this document useful (0 votes)
21 views3 pages

Read and Load Simulator

This code defines functions to load data from a file into an array, print the array contents, and provide a menu-driven interface to call these functions. It declares variables including an array and file pointer, defines functions load() and print() to open a file, read integers into the array, and output the array. The main() function presents a menu and uses switch to call load() based on user input, with plans to later add print and other options.

Uploaded by

Harshit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Read and Load Simulator

This code defines functions to load data from a file into an array, print the array contents, and provide a menu-driven interface to call these functions. It declares variables including an array and file pointer, defines functions load() and print() to open a file, read integers into the array, and output the array. The main() function presents a menu and uses switch to call load() based on user input, with plans to later add print and other options.

Uploaded by

Harshit Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>
#include<stdlib.h>
char fname[20];
FILE *fp;
int mem[100],pc;
void load()
{
printf("Enter file name:");
scanf("%s",fname);

fp = fopen(fname,"r");
if(fp==NULL)
{
printf("File %s not found.\n",fname);
exit(1);
}

while(fscanf(fp,"%d",&mem[pc])!=-1)
pc++;

source type of data target


void Print()
{ int i;
for(i=0;i<pc;i++)
    {
        printf("%06d/n  ", mem[i]);
    }
                  
}
fclose(fp);
}

int main()
{
int ch;

while(1)
{

printf("1.Load\n2.Print\n3.Run\n4.Exit\n");
printf("Enter your choice (1-4):");
scanf("%d",&ch);
switch(ch)
{
Case 1:
Load();
break;
// Case 2:
//Case 3:
//Case 4:
default:
printf(“Invalid choice”);
}

}
}
mem

0 09020
1 09021
2
… ….

99

First Step:
Start from main function

You might also like