Click here to Skip to main content
15,890,557 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: turbo c codes.. need help Pin
David Crow9-Oct-09 7:45
David Crow9-Oct-09 7:45 
GeneralRe: turbo c codes.. need help Pin
CPallini9-Oct-09 8:27
mveCPallini9-Oct-09 8:27 
GeneralRe: turbo c codes.. need help Pin
Tabang9-Oct-09 19:07
Tabang9-Oct-09 19:07 
GeneralRe: turbo c codes.. need help Pin
Tabang9-Oct-09 19:04
Tabang9-Oct-09 19:04 
AnswerRe: turbo c codes.. need help Pin
Tabang9-Oct-09 12:59
Tabang9-Oct-09 12:59 
GeneralRe: turbo c codes.. need help Pin
theCPkid9-Oct-09 22:57
theCPkid9-Oct-09 22:57 
AnswerRe: turbo c codes.. need help Pin
CPallini9-Oct-09 12:18
mveCPallini9-Oct-09 12:18 
AnswerRe: turbo c codes.. need help Pin
theCPkid9-Oct-09 22:48
theCPkid9-Oct-09 22:48 
I know what you want. Just tell me if I am correct.

int main(void)
{
    int a,b,c;
    scanf("%d,%d,%d",&a, &b, &c);
    printf("\nYou just entered: %d, %d, %d", a, b, c);
}


Pay special attention to the commas used inside the scanf function. I think it addresses your doubt to some extent. I had this doubt all my life.

Second, I suppose you will say that above program is very rigid as it allows input of only 3 variables. What if the no. of variables is not known.

Very valid question, I say. Only I have forgotten how to work with console and it give me creeps to find out about gets etc. See this [^]

#include "stdio.h"
#include "stdlib.h"
#include "string.h"

int main(void)
{
	char input[255]; // = malloc( 255*SIZEOF(INT)); //[] = "22, 33, 44, 55, 55, 33";
	int sum = 0;
	int num = 0;

	gets(input);
	char* token;
	token = strtok(input, ",");
	
	/* loop until finishied */
	while (token != NULL)
	{
		sum += atoi(token);
		++ num;
		token = strtok(NULL, ",");
	}
	printf("\nSum = %d, average = %f\n", sum, (num==0? 0 : (float)sum/num));
    return 0;
}


Hope it helps?
GeneralRe: turbo c codes.. need help Pin
Tabang10-Oct-09 6:13
Tabang10-Oct-09 6:13 
GeneralRe: turbo c codes.. need help Pin
Tabang10-Oct-09 6:58
Tabang10-Oct-09 6:58 
GeneralRe: turbo c codes.. need help Pin
theCPkid10-Oct-09 15:50
theCPkid10-Oct-09 15:50 
QuestionFIle handling. turbo c Pin
Tabang9-Oct-09 6:53
Tabang9-Oct-09 6:53 
QuestionRe: FIle handling. turbo c Pin
David Crow9-Oct-09 7:50
David Crow9-Oct-09 7:50 
AnswerRe: FIle handling. turbo c Pin
CPallini9-Oct-09 12:08
mveCPallini9-Oct-09 12:08 
GeneralRe: FIle handling. turbo c Pin
Tabang9-Oct-09 12:48
Tabang9-Oct-09 12:48 
GeneralRe: FIle handling. turbo c Pin
Tabang9-Oct-09 12:57
Tabang9-Oct-09 12:57 
QuestionHow can i convert a .doc file to .html Pin
SNArruda9-Oct-09 5:22
SNArruda9-Oct-09 5:22 
AnswerRe: How can i convert a .doc file to .html Pin
Code-o-mat9-Oct-09 6:37
Code-o-mat9-Oct-09 6:37 
AnswerRe: How can i convert a .doc file to .html Pin
David Crow9-Oct-09 7:28
David Crow9-Oct-09 7:28 
QuestionHow to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 4:20
moh.hijjawi9-Oct-09 4:20 
AnswerRe: How to update a field in an DB using MFC Pin
David Crow9-Oct-09 4:48
David Crow9-Oct-09 4:48 
GeneralRe: How to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 5:33
moh.hijjawi9-Oct-09 5:33 
QuestionRe: How to update a field in an DB using MFC Pin
David Crow9-Oct-09 5:38
David Crow9-Oct-09 5:38 
AnswerRe: How to update a field in an DB using MFC Pin
moh.hijjawi9-Oct-09 5:46
moh.hijjawi9-Oct-09 5:46 
QuestionSearching item in second column list control using find function Pin
Le@rner9-Oct-09 2:37
Le@rner9-Oct-09 2:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.