Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<ctype.h>
- int main(int argc,char **argv)
- {
- char ch;
- char *file_name;
- file_name=(char *)malloc(255*sizeof(char));
- FILE *fp;
- printf("Enter the name of file you wish to see\n");
- gets(file_name);
- fp = fopen(file_name,"r"); // read mode
- if( fp == NULL )
- {
- perror("Error while opening the file.\n");
- exit(EXIT_FAILURE);
- }
- printf("The contents of %s file are :\n", file_name);
- int j=0;
- int i=0;
- int **table;
- int k;
- table = malloc(sizeof(int *) * 3);
- for (i = 0; i < 3; i++)
- {
- *(table + i) = malloc(sizeof(int) * 100000);
- }
- char string[10];
- int q=0;
- while( ( ch = fgetc(fp) ) != EOF )
- {
- if(!isspace(ch))
- {
- string[q]=ch;
- printf("%c",string[q]);
- q++;
- }
- else
- {
- printf("%c",string[q]);
- // table[i][j]=atoi(string);
- memset(string, 0, sizeof string);
- j++;
- q=0;
- }
- if(ch=='\n')
- {
- j=0;
- i++;
- q=0;
- }
- }
- fclose(fp);
- free(file_name);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement