Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main()
- {
- FILE *fp;
- char fname[101]=""; //Used for storing the full path of the file name.
- int buffer = 101;
- int n;
- char c;
- int ch;
- int lineCount=0;
- //int size_in_bytes=(n*sizeof(char*) + (allocated));
- printf("Enter the file name: ");
- scanf("%s", fname);
- printf("\n Data is loaded");
- //printf("\n Allocated space for storing the data: %7d B ( %d char and %d pointers)",size_in_bytes, allocated, n);
- printf("\n Pointer size: %d Bytes\n", sizeof(char *));
- fp=fopen(fname,"r");
- if(fp==NULL)
- {
- printf("\n%s\" File NOT FOUND!",fname);
- getch();
- exit(1);
- }
- printf("\n\nOriginal Data:\n");
- while(!feof(fp) ){
- fgets(fname,100,fp); //Reads text until a new line
- printf("%s", fname);
- if(fname == '\n'){
- lineCount++;
- }
- }
- printf("\nn=%d" , lineCount);
- //int allocated=strlen(fname);
- //printf("\n%d" , allocated);
- fclose(fp);
- //assign an array of char pointers, and then for each pointer assign enough memory for the string
- char **namesFromFile;
- namesFromFile= malloc(n*sizeof(char*));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement