Help!!!

This is a discussion on Help!!! within the C Programming forums, part of the General Programming Boards category; I'm new to C programming. I was stuck this quesiton. I dont knwo what to do. please gimme some hints. ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    6

    Help!!!

    I'm new to C programming. I was stuck this quesiton. I dont knwo what to do. please gimme some hints. thx

    ***********
    *Question:*
    ***********
    Each time you try to read 3 numbers with scanf, check to see if it actually read 0, 1, 2, 3 values. Of course, scanf will terminate only if it receives 3 valid integers, or something that it can't parse as an integer. If scanf receives
    "garbage", our program must dispose of all of the characters that remain on that line of input by reading them and ignoring them. while (getchar() != '\n'); will loop through to the end of a line to get you past any "garbage" remaining on the line.

    Example:
    (You don't have to use this exact format. Your output may look very different from this example as long as it satisfies the
    requirements from the book.)

    Enter a series of integers separated by white space
    They will be used in groups of three
    4 9 8
    The sum of 4, 9, and 8 is 21

    -4 -9 -8
    The sum of -4, -9, and -8 is -21

    4 -8 9
    The sum of 4, -8, and +9 is 5

    4 --8
    4 was only value read. Flushing the line.


    4 8 o12
    Only 4 and 8 were read. Flushing the line.

    the end
    Program session ended due to no more input value

    ********************************
    ****My Codes********************
    ********************************
    #include <stdio.h>
    #include <stdlib.h>

    int main() {
    int input1, input2, input3,c,count;
    int sum = input + input 2+ input3;
    printf("Enter a seies of integers separated by white space\n");

    while (count <3){
    if((c = scanf("%d%d%d",&input1,&input2,&input3)) != 2)
    { if (c ==EOF)
    break;
    }
    else
    {
    while(getchar() != '\n');
    fprintf(stderr, "Invalid inputs\n");
    continue;
    }
    }
    printf("The sum of, %d, %d, and %d is %d, input1,input2,input3,sum);
    return EXIT_SUCCESS;
    }";

  2. #2
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    the error is on this line

    printf("The sum of, %d, %d, and %d is %d, input1,input2,input3,sum);


    Unterminated String Constant - (you need the terminating " )
    your compiler really should have flagged this an error - there may be more but that one stick out
    Monday - what a way to spend a seventh of your life

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21