How are you going to write a C program without a main() function?
How are you going to write a C program without a main() function?
Mainframe assembler programmer by trade. C coder when I can.
How would anyone check if the program worked if you can't use IO functions from the standard library or self-written (you wouldn't be able to output to a file or a terminal window, or anything)?
If it just has to be a C program, then you could make a large comment with several underscores and hyphens between them. Then have the user input the number into the comment where each blank is. It's kind of cheating because the text editor is doing the work, but that's the only solution I can think of.
Last edited by TieFighter; 03-12-2010 at 08:52 PM.
You can use the following code, if you accept the input type as character array. Then the following code will work fine.
Code:#include<stdio.h> main() { char number[15]; printf("Enter the 10 digit numbers\n"); scanf("%s",number); int a,b,c; sscanf(number,"%3d%3d%4d",&a,&b,&c); printf("%d-%d-%d\n",a,b,c); }
Last edited by murugaperumal; 03-12-2010 at 09:47 PM.
You can use the following code. But you need get the input as string.
Code:#include<stdio.h> main() { int number; printf("Enter the 10 digit numbers\n"); scanf("%d",&number); int a,b,c; sscanf(number,"%3d%3d%4d",&a,&b,&c); printf("%d-%d-%d\n",a,b,c); }
I have merged Frost45's and riders29's questions into this thread and renamed this thread "Formatting with hyphens".
Based on what appears to be the ridiculous restriction on what you people can or cannot do, I am inclined to say that claudiu has the right idea: this is really a question about using arithmetic operations to break an integer in decimal representation into its constituent digits.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It creates a char (string) array named "numbers", with up space for up to 15 char's.
Apparently it's hard to get the message across that you can't use char's in your assignment.
So are you guys limited to things like:
number = 987654321
num1 = number % 10
number /= 10
num2 = number % 10
number /= 10
num3 = number % 10
etc. until number == 0
?
Last edited by Adak; 03-16-2010 at 01:54 AM.
What exactly would this do? I'm lost
EDIT: I know what this does now... But I'm still lost as to how I can get one digit at a time.
Eg. If I had 12345 and I wanted '1' to be stored in 'a' , '2' in 'b' , '3' in 'c' .. etc .. how would I do this? Thanks alot!
EDIT 2: Actually I may know how to do what I've described above. If I'm still having troubles I'll post later. Thanks for all your help!!![]()
Last edited by Mini; 03-16-2010 at 03:23 AM.