
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Prof. Varun Sahil to explain Programming concepts at Ankit Institute of Technology and Science. It includes: File, Reading, Sum, Character, Similar, Read, Multiple, Declare, Close, Format, Structured
Typology: Slides
1 / 24
This page cannot be seen from the preview
Don't miss anything!

















#include <stdio.h>void main () {
int num, sum = 0;FILE *inptr;if ((inptr = fopen(“infile”, “r”)) != NULL) {
while(fscanf(inptr, “%d”, &num) != EOF)
sum += num;
fclose(inptr);printf(“The sum of the numbers is %d\n”,sum);
}
}
getc reads from file pointer (fptr) and returns acharacter
Similar to getchar
while ((c = getc(infileptr)) != EOF)
Continues reading characters until it reaches the endof the file
Same as before
Same as before
Creates new file
Overwrites file if it exists
Starts writing at the beginning of the file
Creates new file if it doesn’t exist
Starts writing from the beginning
Starts writing at the end of an existing file
#include <stdio.h>void main () {
int num, sum = 0;FILE *inptr, *outptr;if ((inptr = fopen(“infile”, “r”)) != NULL) {
while(fscanf(inptr, “%d”, &num) != EOF)
sum += num;
fclose(inptr);if ((outptr = fopen(“outfile”, “w”)) != NULL) {
fprintf(outptr,“The sum of the numbers is %d\n”,sum);fclose(outptr);
}
}
}
putc writes a character to file pointer (fptr)Similar to putchar
putc(‘\n’, outfileptr);
Writes a newline to the file
MainMemory(RAM)
Input
Devices
Output Devices Auxiliary
Storage
CPU
ControlUnit (CU) Arithmetic-Logic Unit
(ALU)
Memory
Addresses
0 - 34 - 7
100 -107108 -
110 -
..
instr instr
- 254
.
...
101.
data
program
E.g. char mychar = ‘z’;
mychar
Address = 0x0defa
z
value = value – increment;
increment value
MemoryAddresses
VariableNames
c
d
int
x
=
5,
y
=
10;
float
f
=
12.5,
g
=
9.8;
char
c
=
‘c’,
d
=
‘d’;
docsity.com
defining marks will allocate a memory space forthe variable, xptr now has the address of thevariable marks