Question of White space

This is a discussion on Question of White space within the C Programming forums, part of the General Programming Boards category; Hello world wonder if someone can offer an explanation. I wrote a program, very basic as I'm still learning. The ...

  1. #1
    Registered User terryrmcgowan's Avatar
    Join Date
    Jun 2003
    Posts
    8

    Question of White space

    Hello world

    wonder if someone can offer an explanation.
    I wrote a program, very basic as I'm still learning. The program read
    5 values into an array and added them together finishing by printing the result
    as shown below. On first run I input 1-5 expecting the answer 15, the value it
    returned was very different indeed.

    printf("The sum total is %d",sum);

    after lots of head scratching I tried a space between %d and " this cured
    the problem.

    The next day I wrote another program to read in a value and cube it. The
    program just hangs after the input of the variable x until another number/character
    is entered, however, the output is as it should be. This time the problem was
    cured by removing the space either side or the %d in the scanf statement.


    printf("Please enter the number");
    scanf(" %d ",&x);
    y = x*x*x;
    printf("The cube is %d ",y);

    Finally to the point, all the texts I've read say "C ignores white space",
    is this a problem with the compiler (Bloodshed Dev++) or is it just part of the
    syntax that needs to be considered.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    This FAQ might give you a pointer in the right direction:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    DavT
    -----------------------------------------------

  3. #3
    codemaste
    Guest
    Have you tried to read up on the compilers instructions.

    Also, have you tried another compiler?

    ---

    When I get a chance I will compile your code
    and see if I get the same results.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    14
    Have you tried to read up on the compilers instructions.

    Also, have you tried another compiler?

    ---

    When I get a chance I will compile your code
    and see if I get the same results.

    --KEYBOARD PROBLEM

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. how to skip white space?
    By kalamram in forum C Programming
    Replies: 9
    Last Post: 06-17-2006, 01:57 PM
  3. Input from file no white space characters
    By Dan17 in forum C++ Programming
    Replies: 5
    Last Post: 05-09-2006, 08:28 AM
  4. Passing classes question
    By Daggie in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 11:09 AM
  5. Reading in text file into an array, white spaces...
    By error in forum C++ Programming
    Replies: 12
    Last Post: 01-14-2003, 08:39 AM

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