Help me please in using fscanf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ranioo
    New Member
    • Mar 2008
    • 2

    Help me please in using fscanf

    Hello everybody:
    i'm a new member in this site and i realy have a problem with c++.
    ok my problem is :
    i want to read text from a file and the text contains characters and decimal and hexadecimal using fscanf but when i debug (run the program) i only get smiley faces...??? but when i used getc() it worked ok!!! but the homework is with using fscanf()??????
    this my program and i hope someone responds very fast i'm running out of time???

    [CODE=cpp]#include <stdio.h>
    #include <iostream.h>
    #include <conio.h>

    main()
    {

    FILE *fptr;
    fptr=fopen("c:\ \Lab4.txt","r") ;

    if (!fptr) cout<<"error openning file\n";

    char ch;


    while (!feof(fptr))
    {

    ch=fscanf(fptr, "%c",&ch);
    cout<<ch;

    }



    fclose(fptr);

    getch();
    }[/CODE]

    please help>>>
    Last edited by Ganon11; Mar 25 '08, 10:06 PM. Reason: Please use the [CODE] tags provided.
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    I'm confused - you say you are using C++, but I see all sorts of C-type code in here: stdio.h and fscanf are both C, not C++. In addition, you use <iostream.h>, which is deprecated.

    You should instead use cstdio for stdio.h, iostream for iostream.h, and instead of messing with C-style file manipulation, look up ifstreams and ofstreams.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Try scanf() into an int.

      Comment

      • Ranioo
        New Member
        • Mar 2008
        • 2

        #4
        Hello
        Thank you all for your help...
        but i have figured out my problem ,but thanks anyway...

        Comment

        Working...