Results 1 to 4 of 4

Thread: How to store space in a array in a C program

  1. #1
    Join Date
    Nov 2009
    Posts
    359

    How to store space in a array in a C program

    Well i am not so new with the 'C' programming language, but after trying hard to debug, i still cannot get why my code unable to print spaces when i dont see any problems with it

    code :
    Code:
    while( i < 10)
    {
    arr[i] = (char)" ";
    i++;
    }
    Last edited by NetworkeR; 03-11-2009 at 12:27 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to store space in a array in a C program

    The code looks good, but please check if you initialized the integer variable "i" before you used it in the while loop, also what is the size of the array that you have declared. also check if all the braces used are properly placed.. Please let me know if the "spaces" are still not printed.

  3. #3
    Join Date
    Nov 2009
    Posts
    359

    Re: How to store space in a array in a C program

    kelfro I have checked those several times. The integer variable "i" has been initialized to "0", the array "arr" has been declared so as to save "10" characters. Also all the braces are at their respective places. Now what...???

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to store space in a array in a C program

    Theres a lot of difference between" " and ' '. ' ' is how the space character is denoted whereas " " is a string which is totally different from the space character which you want to print. so if you just replace the " " with ' ', your program should give you 10 spaces in the array that you need.
    code:
    Code:
    while( i < 10)
    {
    arr[i] =' ';
    i++;
    }
    Let me know if there are still any problems with this code fragment.
    Last edited by MindSpace; 03-11-2009 at 12:45 PM.

Similar Threads

  1. Not enough space to store temporary Windows installation files
    By UselessGuy in forum Operating Systems
    Replies: 3
    Last Post: 17-12-2010, 06:44 AM
  2. Program to print an 2D array
    By Sarfaraj Khan in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 02:59 PM
  3. Store content of file in array of bytes
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 21-01-2010, 01:25 PM
  4. How to store byte array to database with JDBC?
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 23-09-2009, 10:52 AM
  5. Three Dimensional Array program in Java.
    By nonose in forum Software Development
    Replies: 3
    Last Post: 10-08-2009, 07:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,718,031,994.30979 seconds with 16 queries