So I've declared a 2d array and want to display its rows one by one.But when I execute the following code I see all the rows in the matrix starting from the one I require.
Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
char topics[3][10]={"Literature","Science---","Sports----"};
void main()
{
clrscr();
cout<<topics[0][0]<<endl<<topics[1][0]<<endl<<topics[2][0]<<endl;
puts(topics[0]);
cout<<endl;
puts(topics[1]);
getch();
}
Output:
L
S
S
LiteratureScience---Sports----
Science---Sports----
What I want my program to do is that when puts(0) is executed, only 'Literature' should be displayed and when puts(1) is executed, only 'Science---' is displayed.
I am a beginner. Please suggest what corrections should I make.Thank you. :)