In any programming language, an array is a list of items ordered sequentially (one after another).
C arrays require that each item in an array is of the same type. To declare an array called intlist of ten integers, for instance, the following statement is used:
int intlist[10];
You can access the first item in intlist by using intlist[0], since all array indexes in C are zero-based. The last item is accessed using intlist[9] - 0 to 9 makes for 10 total integers.
A string, like a day of the week for instance, in C is an array of characters. C treats all strings as zero-terminated or NUL-terminated - the last index contains the value 0, which is called NUL (which is not to be confused with NULL, with two L's, which is used for pointers).
The following two string definitions result in the same data:
char hellostr[6]="Hello";
char hellostr[6]={'H', 'e', 'l', 'l', 'o', 0};
Alternately, and this is under C, you can also use:
char *hellostr="Hello";
Under C++, you would need to use:
const char *hellostr="Hello";
But that's outside the realm of this discussion.
What this does is forces the compiler to allocate memory for "Hello" (a string constant) followed by the value 0 (zero), and then point hellostr to the location of that string constant.
That takes care of strings. Now, for arrays of strings.
What the exercise is expecting you to do is store the name of each day in a week (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday) in a string. This requires an array of 7 strings.
Because a string is an array of characters, you will need an array of an array of strings. Fortunately, string constants come to the rescue. If I wanted to store a list of colors, I could use the following definition:
char *colorlist[6]={"Red", "Orange", "Yellow", "Green", "Blue", "Purple"};
Then use the following code to access the colors in a loop:
for (count=0; count<6; count++)
printf("%s is a fine color!\n", colorlist[count]);
All you have to do now is code the main() function, replace some strings, add a variable declaration, compile, test and debug as required. Be sure to rename the variable colorlist as well to avoid confusion,
See the related links below for some handy C tutorials. Choose one (or more) which best suit(s) your needs.
int main (void)
{
puts ("Monday Tuesday Wednesday Thursday Friday Saturday Sunday");
return 0;
}
To write a C++ program to display the student details using class and array of object.
Write a program which takes the temperature in farhenheight.the program should display the farhenheight temperature as well as centigrade. C= (f-32)*5/9
A C++ program can be used to write C programs that will display 10 lines of biodata. Many types of C programming can be written with a C++ program.
dono
You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.
write a program to display your name age class schoolname e-mail 2hobby based on choice
Faisal
To write a C++ program to display the student details using class and array of object.
Write a program which takes the temperature in farhenheight.the program should display the farhenheight temperature as well as centigrade. C= (f-32)*5/9
A C++ program can be used to write C programs that will display 10 lines of biodata. Many types of C programming can be written with a C++ program.
dono
#include<stdio> #include<conio> class program { namespace display { console.println("write your text"); } } correct me if im wrong im a new programmer.
You need to specify the language in which you want the subtraction of the two matrix in two dimension array written.
write a java program to display "Welcome Java" and list its execution steps.
By learning how to program on C+.
i dont no string for servlate
Write a program which takes any number of days from the user. the program should display the number of years, number of months formed by these days as well as the remaining days.