Advertisement
Guest User

asd

a guest
Feb 27th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<ctype.h>
  5. int main(int argc,char **argv)
  6. {
  7.  
  8. char ch;
  9. char *file_name;
  10. file_name=(char *)malloc(255*sizeof(char));
  11.    FILE *fp;
  12.  
  13.    printf("Enter the name of file you wish to see\n");
  14.    gets(file_name);
  15.  
  16.    fp = fopen(file_name,"r"); // read mode
  17.  
  18.    if( fp == NULL )
  19.    {
  20.       perror("Error while opening the file.\n");
  21.       exit(EXIT_FAILURE);
  22.    }
  23.  
  24.    printf("The contents of %s file are :\n", file_name);
  25.     int j=0;
  26.     int i=0;
  27.     int **table;
  28.     int k;
  29.    
  30.    
  31.     table = malloc(sizeof(int *) * 3);
  32.  
  33.     for (i = 0; i < 3; i++)
  34.         {
  35.         *(table + i) = malloc(sizeof(int) * 100000);
  36.         }
  37.     char string[10];
  38.    
  39.     int q=0;
  40.    while( ( ch = fgetc(fp) ) != EOF )
  41.    {
  42.   if(!isspace(ch))
  43.       {
  44.            string[q]=ch;
  45.            printf("%c",string[q]);
  46.            q++;
  47.       }  
  48.       else
  49.        {   
  50.             printf("%c",string[q]);
  51.         //  table[i][j]=atoi(string);
  52.             memset(string, 0, sizeof string);
  53.             j++;
  54.             q=0;
  55.        }
  56.        if(ch=='\n')
  57.        {
  58.            j=0;
  59.            i++;
  60.            q=0;
  61.        }
  62.        
  63.    }
  64.    fclose(fp);
  65. free(file_name);
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement