Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. /* File: newNames.c
  2. Saves names to file called names2.txt
  3. Author:
  4. Date Created:
  5. */
  6. #include<stdio.h>
  7. int main()
  8. {
  9. FILE *addNames;
  10.  
  11. addNames = fopen("names2.txt", "w");
  12. fprintf(addNames, "Jason\n");
  13. fprintf(addNames, "Cesca\n");
  14. fprintf(addNames, "Stacey\n");
  15. fprintf(addNames, "Mckay\n");
  16. fclose(addNames);
  17. return 0;
  18. }
  19.  
  20.  
  21. // Read to a File
  22.  
  23. #include<stdio.h>
  24. int main()
  25. {
  26. FILE *display;
  27. char name[100];
  28. display = fopen("names2.txt", "r");
  29. while(fgets(name, 100, display)!=NULL)
  30. {
  31. printf("%s", name);
  32. }
  33. fclose(display);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement