just want to ask if this is an array program????...
my professor told us to make array program that displays 10 names..
my professor tells us that we can use C or C++ program..
i prefer using C cause im much familiar with C programs...

Output:
fdgdfg
dfgdfg
dfgdfg
dfgdfg
dfgdfgd
dfgdfg
dfgdfgd
dfgdfgd
dfgdgdf
dfgdfg

this is what i did:

#include<stdio.h>
#include<conio.h>
#include<string.h>

char names[10];
int n;

void main()
{
    clrscr();
    printf("Input 10 Names:\n");
    for(n=0;n<10;n++){
    scanf("%s",n);}
    getch();
}

the program produces output which i inputed.
i think its ok..
but im not sure if this is an Array program..
i think i just use the basic C program...
and also, i think i had just used for loop and nothing else...
do you think i just used a simple C program that display names without having any for loops or Arrays???...

please help me.. im confuse...

>i prefer using C cause im much familiar with C programs..
Clearly you aren't.

>#include<conio.h>
Please don't waste your time with this garbage.

>#include<string.h>
Why include a header that you're not using?

>char names[10];
>int n;
Global variables should be avoided. Also, names is poorly named as it defines a single array when you probably wanted an array of arrays.

>void main()
int main ( void )

>clrscr();
Unnecessary, non-portable, anti-social, need I go on?

>scanf("%s",n);}
n is not your array, names is. Also, using %s with scanf is equivalent to gets, which is well known to be a huge mistake. Use the field width modifier to make sure that you don't overflow the array.

>getch();
There are portable ways to do this.

Let's look at the fixed code:

#include<stdio.h>

int main ( void )
{
  char names[10][20];
  int i;

  printf ( "Input 10 Names: " );

  for ( i = 0; i < 10; i++ )
    scanf ( "%19s", names[i] );

  /* Clean up the stream */
  while ( getchar() != '\n' )
    ;

  /* Pause */
  getchar();

  return 0;
}

thakz anyway... have a nice day... just want to ask.. why is there a "19" in your scanf("19%s",names);?..

im just a biggener to this kind of subject..

>>char names[10][20];
for practical purposes this means names is an array that can hold up to 10 names. Each name can have up to 19 visible char and a terminal null char to make it a null terminated char array instead of just a char array.

ok tnx so much... what about the " char[10][20] " whats the porpuse of putting [20]?.... im quite confiuse on this one..

>what about the " char[10][20] " whats the porpuse of putting [20]?
char a[20] gives you an array of 20 characters, right? What if you want ten of them? Sure, you could do this:

char a[20];
char b[20];
char c[20];
char d[20];
...

But that reminds you of the same problem that's solved by making an array of characters. So you add another dimension to the array and make it an array of 10 arrays of 20 characters:

char a[10][20];

If it helps, you can look at an array as a vector:

[0][1][2][3][4][5][6][7][8][9]

And a two dimensional array as a table:

[0,0][0,1][0,2][0,3][0,4][0,5]...[0,18][0,19]
[1,0][1,1][1,2][1,3][1,4][1,5]...[1,18][1,19]
[2,0][2,1][2,2][2,3][2,4][2,5]...[2,18][2,19]
[3,0][3,1][3,2][3,3][3,4][3,5]...[3,18][3,19]
[4,0][4,1][4,2][4,3][4,4][4,5]...[4,18][4,19]
[5,0][5,1][5,2][5,3][5,4][5,5]...[5,18][5,19]
[6,0][6,1][6,2][6,3][6,4][6,5]...[6,18][6,19]
[7,0][7,1][7,2][7,3][7,4][7,5]...[7,18][7,19]
[8,0][8,1][8,2][8,3][8,4][8,5]...[8,18][8,19]
[9,0][9,1][9,2][9,3][9,4][9,5]...[9,18][9,19]

A three dimensional array would be a cube, and a four dimensional array would be a vector of cubes, then a five dimensional array would be a table of cubes, and so on. But you rarely need more than two dimensions. ;)

>>char names[10][20];
for practical purposes this means names is an array that can hold up to 10 names. Each name can have up to 19 visible char and a terminal null char to make it a null terminated char array instead of just a char array.

ya it's string example

commented: Thanks. Don't bump old threads. -1
commented: Zero value and four years too late. Wonderful first post... -4
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.