| | |
did I used Array???
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
just want to ask if this is an array program????...
my professor told us to make array program that displays 10 names..
He also tells us that we can use C or C++ program..
i prefer using C cause im much familiar with C programs...
my knowledge in Array is not quite good...
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...
or i just used a for loop and nothing else..
did I only used for loop and nothing else? or just a simple C program that do not have any of for loops or Array...
please help me.. im confuse...
my professor told us to make array program that displays 10 names..
He also tells us that we can use C or C++ program..
i prefer using C cause im much familiar with C programs...
my knowledge in Array is not quite good...
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...
or i just used a for loop and nothing else..
did I only used for loop and nothing else? or just a simple C program that do not have any of for loops or Array...
please help me.. im confuse...
Last edited by mccbebz; Mar 14th, 2006 at 12:22 pm. Reason: Add somthing
>> char names[10];
>>scanf("%s",n);}
the above is incorrect.
1. you need and array of 10 strings. What you posted is one array of 10 characters.
you have to pass a character array, not an integer
One major problem with scanf() is that you can type as many characters into the string as you want and scanf() will simply overwrite your buffer with no bounds checking. This will probably cause your program to crash. fgets() is better than scanf() because fgets() you can tell it how many caracters to accept.
>>scanf("%s",n);}
the above is incorrect.
1. you need and array of 10 strings. What you posted is one array of 10 characters.
you have to pass a character array, not an integer
char names[10][10]; for(n=0;n<10;n++){ scanf("%s",names[n]);} }
One major problem with scanf() is that you can type as many characters into the string as you want and scanf() will simply overwrite your buffer with no bounds checking. This will probably cause your program to crash. fgets() is better than scanf() because fgets() you can tell it how many caracters to accept.
•
•
Join Date: Mar 2006
Posts: 5
Reputation:
Solved Threads: 0
I have change my program as what you have told me and produces the same output....
well, the most important is that, do i have now an Array program??.
#include<stdio.h>
#include<conio.h>
char names[10][10];
int n;
void main()
{
clrscr();
printf("Input 10 Names:\n);
for(n=0;n<10;n++){
scanf("%s",names[n]);}
getch();
}
is this now an Array program???
all i know is that if you use somthing like this " Names[][][] " it means you used array.. am i right? or is there any other possible discription on Array....
well, the most important is that, do i have now an Array program??.
#include<stdio.h>
#include<conio.h>
char names[10][10];
int n;
void main()
{
clrscr();
printf("Input 10 Names:\n);
for(n=0;n<10;n++){
scanf("%s",names[n]);}
getch();
}
is this now an Array program???
all i know is that if you use somthing like this " Names[][][] " it means you used array.. am i right? or is there any other possible discription on Array....
![]() |
Similar Threads
- Can I ghost a RAID array??? (Windows NT / 2000 / XP)
- Creating dynamic array structures (C++)
- Array limit (C)
- struct dynamic 2d array alloc (C)
- string to integer array transformation (C)
- Array (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Is This an Array Program???
- Next Thread: Pls help me ;'=' : 'unsigned char ' differs in levels of indirection from 'void *'
Views: 1366 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






