conversion int to char, char to int ????? 
Author Message
 conversion int to char, char to int ?????

Could someone please help me with this simple comparison exercise ???

I am reading in a char using

result = scanf("%s",y);

"y" will always be a number but I had trouble reading input as an int so

I am using the scanf.

I then have an int "x" that I need to do a comparison with "y".

I know I am overlooking something.

What is the best way to do this comparison ?

Thanks in advance,
Tim.

  tmetzger.vcf
< 1K Download


Tue, 28 May 2002 03:00:00 GMT  
 conversion int to char, char to int ?????

A simple atoi did the trick.

I could have sworn I tried that.  Oh well, at least I'm off that problem.

Thanks,
Tim.

Quote:

> Could someone please help me with this simple comparison exercise ???

> I am reading in a char using

> result = scanf("%s",y);

> "y" will always be a number but I had trouble reading input as an int so

> I am using the scanf.

> I then have an int "x" that I need to do a comparison with "y".

> I know I am overlooking something.

> What is the best way to do this comparison ?

> Thanks in advance,
> Tim.

  tmetzger.vcf
< 1K Download


Tue, 28 May 2002 03:00:00 GMT  
 conversion int to char, char to int ?????
Why did you have trouble with the following?

    int intvar;
    scanf("%d", &intvar);

Is it because you neglected to use &intvar and just used intvar?



Tue, 28 May 2002 03:00:00 GMT  
 conversion int to char, char to int ?????

Quote:

> A simple atoi did the trick.

> I could have sworn I tried that.  Oh well, at least I'm off that problem.

> Thanks,
> Tim.


> > Could someone please help me with this simple comparison exercise ???

> > I am reading in a char using

> > result = scanf("%s",y);

If y is declared as char*, this will read it in as a string, with no
check for
overflow.

If y is a char, you need scanf("%c", &y) or y=getchar();.

In either case, result will be set to the number of characters read;
this is unlikely to be what you want, judging purely from the name
of the variable.

Quote:

> > "y" will always be a number but I had trouble reading input as an int so

> > I am using the scanf.

This suggests serious confusion.  Please post a minimal example of what
you are trying to do.

Quote:

> > I then have an int "x" that I need to do a comparison with "y".

> > I know I am overlooking something.

You can't (directly) compare int's with char*'s in any sensible way/

Quote:

> > What is the best way to do this comparison ?

> > Thanks in advance,
> > Tim.

--
Trevor Walker,   Emtex Ltd.
70 St Albans Rd., Watford, Hertfordshire, UK
Tel +44 (0)1923 242420


Tue, 28 May 2002 03:00:00 GMT  
 conversion int to char, char to int ?????
Your question is not clear and answer seems not connected.
Quote:

> A simple atoi did the trick.

> I could have sworn I tried that.  Oh well, at least I'm off that problem.

> Thanks,
> Tim.


> > Could someone please help me with this simple comparison exercise ???

> > I am reading in a char using

> > result = scanf("%s",y);

> > "y" will always be a number but I had trouble reading input as an int so

> > I am using the scanf.

> > I then have an int "x" that I need to do a comparison with "y".

> > I know I am overlooking something.

> > What is the best way to do this comparison ?

> > Thanks in advance,
> > Tim.



Tue, 28 May 2002 03:00:00 GMT  
 conversion int to char, char to int ?????

Quote:


>> A simple atoi did the trick.

>> I could have sworn I tried that.  Oh well, at least I'm off that problem.

>> Thanks,
>> Tim.


>> > Could someone please help me with this simple comparison exercise ???

>> > I am reading in a char using

>> > result = scanf("%s",y);

>If y is declared as char*, this will read it in as a string, with no
>check for
>overflow.

>If y is a char, you need scanf("%c", &y) or y=getchar();.

>In either case, result will be set to the number of characters read;

No, the return value of scanf() is the number of arguments successfully
written to excluding thise for the %n specifier. It can also be EOF
when input failure occurs before any conversion takes place.

--
-----------------------------------------


-----------------------------------------



Wed, 29 May 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. int to char / char to int

2. char to int, int to char...

3. char *fnpars(const char *fn, int p, int v)

4. int gethostname(char FAR* name, int len)

5. int main( int argc, char *argv[] )

6. int to char type conversion????

7. conversion from int to char

8. unsigned char --> int conversion

9. int to char conversion

10. int to char conversion

11. scaning a char and outputing char, int, float??

12. Portable char to int conversion?

 

 
Powered by phpBB® Forum Software