Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gillian Herschlag
- // Worked with: Peter Petas, Joe Demich, and Mike Wynn
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main() {
- // grab the file
- FILE *filep;
- //access file
- char nameOfFile[255];
- printf("%s", "File Name: ");
- scanf("%s", nameOfFile);
- filep = fopen(nameOfFile, "r");
- char sline[50];
- //puts each char into sn array full of characters
- while(!feof(filep))
- {
- fgets(sline, 50, filep);
- int index = 0;
- while(i < sline[index]!='\0')
- {
- printf("%c",sline[index]);
- index++;
- }
- //print out what user sees in betwen the name and initials
- printf(" ");
- printf("yields ");
- //check for middle name
- if(sline == NULL) exit(0);
- //get length of name
- int length = strlen(sline);
- // use loop to go through each character
- int i = 0;
- while(i < length)
- {
- //check if for blank
- if(sline[i] == ' '){
- // if next char is not blank, print
- if(i + 1 < length && sline[i + 1] != ' ')
- {
- printf("%c. ", sline[i + 1]);
- }
- }
- i++;
- }
- // print initials
- if(sline[0] != ' ' && sline[0] != '\0') printf("%c.\n", sline[0]);
- }
- fclose(filep);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement