How do you create and print an array of characters
I can't seem to find anything on how to print out an array of characters:
I want to make a table of dashes such as below:
----------
----------
----------
How would I go about doing that?
so far, my code goes like this:
int i, m=0;
char bufferarray [30];
for (i=0; i <31; i++)
{
bufferarray[i] = '\45';
}
for (m=0; m<i; m++)
{
printf("%s \n", bufferarray);
}
Re: How do you create and print an array of characters
Quote:
Originally posted by Unregistered
I can't seem to find anything on how to print out an array of characters:
I want to make a table of dashes such as below:
----------
----------
----------
How would I go about doing that?
so far, my code goes like this:
int i, m=0;
char bufferarray [30];
for (i=0; i <31; i++)
{
bufferarray[i] = '\45';
}
for (m=0; m<i; m++)
{
printf("%s \n", bufferarray);
}
%s expects a NUL ('\0') terminated character arrays ( the '\0' signals the end of the string ) and it prints all the the characters till it finds the NUL character
so , do this instead
Code:
char bufferarray[31];
int i;
for(i=0;i<31;i++) bufferarray[i]='\45';
bufferarray[31]='\0';
printf("%s \n",bufferarray);
the second loop is not requried
Also , most string manipulation functions declared in string.h expect NUL terminated character arrays .