Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <stdlib.h>
- void reads(void);
- FILE * fp;
- int main(void){
- fp=fopen("/Users/amywang/Dropbox/Code/guessinggame/bob.txt","r");
- if (fp==NULL){
- printf("Whoops, something went wrong.\n");
- exit(1);
- }
- reads();
- fclose(fp);
- return 0;
- }
- void reads(void){
- char ch;
- while ((ch=getc(fp))!=EOF){
- if (isalpha(ch)){//it's a letter
- if(isupper(ch)){//uppercase letter
- printf("%c is a letter, and its numerical position is %d.\n", ch, ch-64);
- }
- else if (islower(ch)) {//lowercase letter
- printf("%c is a letter, and its numerical position is %d.\n", ch, ch-96);
- }
- }
- else{
- printf("%d\n", -1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement