I don't mean my line of code. In the program I enter one number and then it goes to a new line. I want a way around this if possible. (Very new to C)
I don't mean my line of code. In the program I enter one number and then it goes to a new line. I want a way around this if possible. (Very new to C)
You mean to type more than one thing and then hit enter?
1 2 3<enter>
Sure, scanf will let you set up formatted input. Your book should be covering that soon.
Quzah.
Hope is the first step on the road to disappointment.
It's probably not impossible but if you show us your code it will be easier to say how.
If by "it goes to a new line" you mean because the user had to hit enter, then you will probably need to use some special terminal library for this; also let us know what OS you are using.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
quzah, it is for an assignment for a class I'm taking. The assignment does not specify if this is needed, I just prefer it. So, if you could, please elaborate?
MK27, here's my code:
My OS is Windows 7 Ultimate.Code:#include <stdio.h> #include "genlib.h" #include "simpio.h" main() { int num1, num2, num3, num4, sum, average; printf ("Your grades were: "); num1 = GetInteger(); num2 = GetInteger(); num3 = GetInteger(); num4 = GetInteger(); sum = num1 + num2 + num3 + num4; average = sum / 4; printf ("The average grade is %d", average); getchar(); }
Last edited by PYROMANIAC702; 07-01-2011 at 04:22 AM.
Hmm, so do you mean the problem quzah pointed out (that the user has to enter the grades one by one)?
We also need to see the GetInteger() function, probably you want to use some combination of scanf() and sscanf() and return a pointer to an int array, or fill in an array submitted as an argument:
Code:int *GetInteger(); // returns pointer to malloc'd array void GetInteger (int *data); // fills in submitted array
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
You are speaking a whole different language to me man... But thanks for your help! I honestly appreciate it.
Yeah the easy way to do this using scanf function. By the time your class cover scanf function. It would look something like this
ssharishCode:scanf("%d %d %d %d", &num1, &num2, &num3, &num4);
Life is like riding a bicycle. To keep your balance you must keep moving - Einstein
Also:
Note the declaration of main and the return value. The main function returns an int to the system, this is required to be C99 compliant. Some suggested reading:Code:#include <stdio.h> #include "genlib.h" #include "simpio.h" int main(void) { ........ return (0); }
How to declare main()
Get a number from the user.