从文件指针获取垃圾值?

时间:2014-11-18 14:15:27

标签: c++

下面是我的代码我想要做的是在数组中存储fptr指向的特定文件中的字符,用户给出了字符将在数组中复制的位置,但总是得到垃圾值。 谁能告诉我为什么会这样? 任何帮助将不胜感激。

void copy()
{
    int i,j,temp=0;
    FILE *fptr;
    count=0;

    cout<<"enter i"<<endl;
    cin>>i;

    cout<<"enter j"<<endl;
    cin>>j;

    i--;j--;

    fptr=fopen("filename","r");
    fseek(fptr,i,SEEK_SET);

    temp=j-i+1;
    char x;
    while(temp--)
    {
        x=getc(fptr);
        cout<<"x="<<x<<endl;
        count++;
    }
}

0 个答案:

没有答案