Solved

urgent: getc...

Posted on 2008-06-25
4
185 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
  • 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test against App 49 137
chcp 65001 File encoding 66 247
Setting nameservers after res_init fails doing res_query 2 98
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 33
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

809 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