Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-11-2009
Member
 
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.
Reply With Quote
  #2  
Old 03-11-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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.
Reply With Quote
  #3  
Old 03-11-2009
Member
 
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...???
Reply With Quote
  #4  
Old 03-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 07:48 PM.