Advertisement
Demich

I love C programming!

Feb 21st, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. // Gillian Herschlag
  2. // Worked with: Peter Petas, Joe Demich, and Mike Wynn
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. int main() {
  8. // grab the file
  9. FILE *filep;
  10.  
  11. //access file
  12. char nameOfFile[255];
  13. printf("%s", "File Name: ");
  14. scanf("%s", nameOfFile);
  15. filep = fopen(nameOfFile, "r");
  16. char sline[50];
  17.  
  18. //puts each char into sn array full of characters
  19. while(!feof(filep))
  20. {
  21. fgets(sline, 50, filep);
  22. int index = 0;
  23.  
  24. while(i < sline[index]!='\0')
  25. {
  26. printf("%c",sline[index]);
  27. index++;
  28. }
  29.  
  30. //print out what user sees in betwen the name and initials
  31. printf(" ");
  32. printf("yields ");
  33.  
  34. //check for middle name
  35. if(sline == NULL) exit(0);
  36.  
  37. //get length of name
  38. int length = strlen(sline);
  39.  
  40. // use loop to go through each character
  41. int i = 0;
  42.  
  43. while(i < length)
  44. {
  45. //check if for blank
  46. if(sline[i] == ' '){
  47. // if next char is not blank, print
  48. if(i + 1 < length && sline[i + 1] != ' ')
  49. {
  50. printf("%c. ", sline[i + 1]);
  51. }
  52. }
  53. i++;
  54. }
  55.  
  56. // print initials
  57. if(sline[0] != ' ' && sline[0] != '\0') printf("%c.\n", sline[0]);
  58. }
  59. fclose(filep);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement