I got this assignment and I'm stuck. I have to write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367. Can someone help?
:confused:
DemonLady 0 Newbie Poster
Recommended Answers
Jump to PostI got this assignment and I'm stuck. I have to write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367. Can someone help?
:confused:This question gets asked about once a week on …
Jump to PostNo, never use scanf. Use fgets or even fread or read, and sscanf maybe. But then, the numbers conversion by sscanf is not specified in standard anyhow. And using %d, the sscanf does some strange things. %d must read int, but when we read into int and then print that …
Jump to PostIndeed, in my limits.h, short int is two bytes, int is four bytes and long int is eight bytes, thanks. And i have always thought that int is two bytes!!! There is information about limits.h, in standard, and there INT_MAX is defined as 32767, and INT_MIN as -32767, and i …
Jump to PostYou still want to use scanf directly, instead of fgets and sscanf, atoi, or even better, strtol. This would cause you trouble at least because of all the input and newlines which scanf would discard, but which remain in the input stream. Much better and easier is to never use …
Jump to PostThis works exactly as for int in 32 bit machine, but reverses longer numbers in 64 bit machine:
#include <stdlib.h> #include <stdio.h> #include <errno.h> int main () { long int r = 0, n; char buf [FILENAME_MAX]; printf ("Enter a number: "); fgets (buf, FILENAME_MAX, stdin); n …
All 21 Replies
Dave Sinkula 2,398 long time no c Team Colleague
swarren74 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
swarren74 0 Newbie Poster
SirJames 10 Newbie Poster
TkTkorrovi 69 Junior Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
TkTkorrovi 69 Junior Poster
vemanamar 0 Newbie Poster
TkTkorrovi 69 Junior Poster
TkTkorrovi 69 Junior Poster
c0ld sn1ff3r -4 Newbie Poster
cutedipti 0 Light Poster
nadim2010 -1 Newbie Poster
jonsca commented: Don't bump old threads -1
nbaztec 45 Posting Pro in Training
Xufyan -4 Posting Whiz
andro23 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
andro23 0 Newbie Poster
ankithajain 0 Newbie Poster
Ajini 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.