Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main()
  6. {
  7. FILE *fp;
  8. char fname[101]=""; //Used for storing the full path of the file name.
  9. int buffer = 101;
  10. int n;
  11. char c;
  12. int ch;
  13. int lineCount=0;
  14.  
  15. //int size_in_bytes=(n*sizeof(char*) + (allocated));
  16.  
  17. printf("Enter the file name: ");
  18. scanf("%s", fname);
  19. printf("\n Data is loaded");
  20. //printf("\n Allocated space for storing the data: %7d B ( %d char and %d pointers)",size_in_bytes, allocated, n);
  21. printf("\n Pointer size: %d Bytes\n", sizeof(char *));
  22.  
  23. fp=fopen(fname,"r");
  24. if(fp==NULL)
  25. {
  26. printf("\n%s\" File NOT FOUND!",fname);
  27. getch();
  28. exit(1);
  29. }
  30.  
  31. printf("\n\nOriginal Data:\n");
  32. while(!feof(fp) ){
  33. fgets(fname,100,fp); //Reads text until a new line
  34. printf("%s", fname);
  35.  
  36. if(fname == '\n'){
  37. lineCount++;
  38. }
  39. }
  40. printf("\nn=%d" , lineCount);
  41.  
  42. //int allocated=strlen(fname);
  43. //printf("\n%d" , allocated);
  44. fclose(fp);
  45.  
  46. //assign an array of char pointers, and then for each pointer assign enough memory for the string
  47. char **namesFromFile;
  48. namesFromFile= malloc(n*sizeof(char*));
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement