?
Solved

urgent: getc...

Posted on 2008-06-25
4
Medium Priority
?
189 Views
Last Modified: 2010-04-15
hi,

to use getc from file, it is like this

c=getc(f) where f is the filepointer...

my problem is that i want to atoi the value read ....

for example if the value is read 2, i want to read 2 and not ascii 50...

could anyone pls help? i tried c=atoi(getc(f)) which is wrong....
0
Comment
Question by:zizi21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 21863742
Something like :
c = getc(f);
int value = -1;
if (isdigit(c)) value = c - '0';

Open in new window

0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 2000 total points
ID: 21863749
Or if you are sure that a digit will be read (and don't want to check that), you can of course just do :
int value = getc(f) - '0';

Open in new window

0
 
LVL 24

Expert Comment

by:fridom
ID: 21863788
something along hte following lines will do:

Regards
Freidrich

#include <stdio.h>
#include <ctype.h>
 
 
int main (void) {
  int i = getchar();
  int num;
 
  if (isdigit(i)) {
    num = i - '0';
  }
  printf("i = %d, num = %d\n", i , num);
 
  return 0;
}

Open in new window

0
 

Author Comment

by:zizi21
ID: 21863887
thanks a million...doing now....
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question