Ctr+D and Few Bugs in Program

This is a discussion on Ctr+D and Few Bugs in Program within the C Programming forums, part of the General Programming Boards category; I am trying to fix a glitch I Have in the program below. I want it to keep looping, which ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    11

    Ctr+D and Few Bugs in Program

    I am trying to fix a glitch I Have in the program below. I want it to keep looping, which is does and after each input from the user (after they hit return) I want it to print only the numbers that they typed in. Once the user types in CTR+D I want the input top stop and then have it display the total and count of all the numbers input. But the CTRL+D doesnt work for my program and I cant figure out why... Will my program even print out the correct count and total values? Thanks for your time and help.

    Here is my code...

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    int main() {

    char delimiters[] = " \t\n\r";
    char storage[100];
    char copy[100];
    char* p;
    int n;
    double x, numbers, counttemp=0, totaltemp=0, count=0, total=0;

    fgets( storage, sizeof(storage), stdin );

    while( storage[0] != EOF ) {
    strcpy(copy, storage);
    p = strtok(copy, delimiters);
    while (p) {
    x = sscanf(p, "%d", &numbers);
    if( x > 0 ) {
    printf("%d\t", numbers);
    totaltemp += numbers;
    counttemp += x;
    }
    p = strtok(NULL, delimiters);
    }
    total += totaltemp;
    count += counttemp;
    counttemp = 0;
    totaltemp = 0;
    printf("\n");
    fgets( storage, sizeof(storage), stdin );
    }
    printf("Total = %d\t\tCount = %d\n", total, count);
    exit(0);
    }

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    11

    One done

    Ok I fixed the CTR+D setup and the total (I beleive), Thanks, but I am still getting a wrong count, Ill keep working at it
    Last edited by scaven; 04-15-2003 at 04:04 PM.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    11

    NEVERMIND

    I found out the rest of my errors!

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