Solved

urgent: getc...

Posted on 2008-06-25
4
187 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 500 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

Industry Leaders: 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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
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 reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

733 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