|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/DiscussionQ3
FILE *f=fopen("nameOfFile", "r");
FILE *f=fopen("nameOfFile", "w");
get char one at a time:
int c;
FILE *f=fopen("nameOfFile", "r");
while( (c=fgetc(f)) != EOF) {
//process the value in c
}
get an integer at a time
int num;
FILE *f=fopen("nameOfFile", "r");
while (1==fscanf(f, "%d", &num)) {
//process the value in num
}
alternate for an integer at a time
int num;
FILE *f=fopen("nameOfFile", "r");
while (fscanf(f, "%d", &num) != EOF) {
//process the value in num
}
Processing characters
1. if variable c is equal to the previous character
count that occurrence
2. if variable c contains an upper case letter convert it to lower case
3 Caeser Cipher
if variable c contains an upper case letter, code it by adding 5 to it.
if that makes c>'Z', then wrap around to the beginning of the alphabet
Processing integers
4. count the number of odd numbers
5. count the number of times variable num is greater than the previous value
6. count the number of times variable num is greater than the sum of the previous two integers
|