while reading a text file which contains repetitive 0,1 and 2 using fgetc ....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shreyav1998
    New Member
    • Aug 2015
    • 1

    while reading a text file which contains repetitive 0,1 and 2 using fgetc ....

    in the following code i am trying to read a file containing 0,1,2 patterns, on running it fails and shows that binary.exe file failed. can anyone suggest :



    #include<stdio. h>
    #include<iostre am>
    #include<conio. h>
    using namespace std;


    int main()
    {
    //clrscr();
    int a[5000][1],t=0,tb=0,tn=0, w=0,tn1=0,z=0,f n=6,x=0,d=0,v;
    int i,n,p[10][1]={3,3,3,3,3,3,3 ,3,3,3},j=0,k=0 ,m=0,l[3][1]={1,1,0},s[5000][1],r=0,bn[10][1],b=0,f=0,result[1000][1] ;

    for(i=0;i<100;i ++)
    {
    result[i][0]=4;
    }
    for (i=0;i<=1000;i+ +)
    { a[i][0]=5; } // input array is filled with 5

    FILE *fp;
    char ch ;

    fp = fopen( "d:\\test file \\test1.txt","r ") ;

    label1: while(1)
    {
    ch= fgetc(fp);
    //printf("%c \n",ch);

    if (ch== EOF)
    break;
    if (ch==' ')
    { goto label1; }
    a[z][0]=ch; // input array is filled with the characters of the file

    printf("%c ",a[z][0]);
    z++;
    }
    w=z;

    printf ("\n number of bits= %d\n",w) ;

    fclose (fp) ;

    getch();

    }
Working...