473,471 Members | 2,017 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help me please in using fscanf

2 New Member
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???

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <iostream.h>
  3. #include <conio.h>
  4.  
  5. main()
  6. {
  7.  
  8.    FILE *fptr;
  9.    fptr=fopen("c:\\Lab4.txt","r");
  10.  
  11.    if (!fptr) cout<<"error openning file\n";
  12.  
  13.    char ch;
  14.  
  15.  
  16.    while (!feof(fptr))
  17.    {
  18.  
  19.          ch=fscanf(fptr,"%c",&ch);
  20.        cout<<ch;
  21.  
  22.    }
  23.  
  24.  
  25.  
  26.    fclose(fptr);
  27.  
  28. getch();
  29. }
please help>>>
Mar 25 '08 #1
3 1813
Ganon11
3,652 Recognized Expert Specialist
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.
Mar 25 '08 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Try scanf() into an int.
Mar 26 '08 #3
Ranioo
2 New Member
Hello
Thank you all for your help...
but i have figured out my problem ,but thanks anyway...
Mar 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Naren | last post by:
Hello All, Can any one help me in this file read problem. #include <stdio.h> int main() {
4
by: danu | last post by:
I'm trying to read data from a file (line by line) and trying to assign the values to the structure members. I'm kind of lost in this case since the books I'm using for reference doesn't give any...
4
by: c_beginner | last post by:
As a mean to improve my C skill for a more of program oriented I started the acm's problem set. In the following code the stdin gets the two inputs but the program does not proceeds further....
9
by: quyvle | last post by:
I can't seem to get this function to work correctly. I'm wondering if anyone could help me out with this. So I'm using the fscanf function to read the input stream and store each string in the...
0
by: nt91rx78 | last post by:
Our college changes 18 weeks semester to 16 semester, so our CS professor cannot finish teaching the last important chapter which is related with my problw\em. This is program C problem Anyone...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
3
by: james121285 | last post by:
I have been trying this program for ages and am not getting very far. I am trying to input data from a seperate file and use it to work out the max and min values of the data. I have done the second...
18
by: Scott | last post by:
Hi, a problem with this following code is really bugging me. tform = fopen(country, "r"); fseek(tform, 9L, SEEK_SET); fgets(player2, 38, tform); printf("Player Name (save): %s", player);...
3
by: Alami | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.