>i prefer using C cause im much familiar with C programs..
Clearly you aren't.
>#include
Please don't waste your time with this garbage.
>#include
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;
} Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401