Changes to file structure for VSCode and bug fixes

This commit is contained in:
Louise Brown
2022-11-14 13:51:40 +00:00
parent 7fd908108a
commit caee190d05
41 changed files with 346 additions and 124 deletions

BIN
LC18/FileMove/data.dat Normal file

Binary file not shown.

48
LC18/FileMove/filemove.c Normal file
View File

@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>
/* Example 3 - jumping & getting element count */
int main(void)
{
int ValRead;
int Item;
int Locn;
FILE *fptr;
/* Open the file from example 1 */
fptr = fopen ("data.dat","rb");
if ( fptr == NULL )
{
printf ("\nError opening input file - aborting ");
exit (0);
}
/* Ask the user which value to jump to */
printf ("\nWhich value do you wish to view ? ");
scanf ("%d",&Item);
/* Jump to this item */
/* notice we move in steps of item size */
Locn = Item * sizeof(int);
fseek (fptr, Locn, SEEK_SET);
/* And read a single integer in */
if (fread (&ValRead, sizeof(int), 1, fptr ) == 1)
{
/* Display the read value */
printf ("Item %d is %d\n",Item,ValRead);
}
else
printf("Failed to read at location %d\n", Item);
/* And close */
fclose (fptr);
/* All Done */
return 0;
}