| | |
Array with names
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
As this is my first post on this forum I want to say "Hello!" to everybody and I hope that we'll help each other as much as we can and we'll be very good friends. 
So, this is my problem ( a rather simple one but I don't know how to resolve it ) : I found a exercise that wants me to have a array with some student's names and another array with their grades ( numerical grades ) at informatics. :eek:
Example: X=('John','Michelle','Jack','Robert'); Y=(10,5,6,7);
My question is: how do I put those names in the array so that a name ( let's say John ) should occupy a single position? For example: X[1]= 'John'; X[2]='Michelle' , etc. I have to read them from the keyboard , of course.
Thank you very much for your time and eventual help!

So, this is my problem ( a rather simple one but I don't know how to resolve it ) : I found a exercise that wants me to have a array with some student's names and another array with their grades ( numerical grades ) at informatics. :eek:
Example: X=('John','Michelle','Jack','Robert'); Y=(10,5,6,7);
My question is: how do I put those names in the array so that a name ( let's say John ) should occupy a single position? For example: X[1]= 'John'; X[2]='Michelle' , etc. I have to read them from the keyboard , of course.

Thank you very much for your time and eventual help!
•
•
Join Date: Sep 2004
Posts: 27
Reputation:
Solved Threads: 0
Hi djextazy,
Well come to DaniWeb ,
if u want to have full name at one location of the array
u have to declare array as a two dimensional array,
i-e its declaration would be like this
char [][];
or u can also use array of pointers , but if u r new to C++ u should use
two dimension array
I hope it resolved ur issue but still if their is some problem feel free to ask again.
Fahad
Well come to DaniWeb ,
if u want to have full name at one location of the array
u have to declare array as a two dimensional array,
i-e its declaration would be like this
char [][];
or u can also use array of pointers , but if u r new to C++ u should use
two dimension array
I hope it resolved ur issue but still if their is some problem feel free to ask again.
Fahad
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by fahad
Hi,
The declaration should be like this
char X[][];
Fahad
a[1][1] = "Victor";
a[2][2] = "Jose"; ???
I mean:
char a[30][30],i,n;
cout<<"n= "; cin>>n;
for(i=1;i<=n;i++) { cout<<"Give "<<i<<"-st name: "; cin>>a[i]; }
Correct me please if I am mistakening. Thank you for your help!
An array of size N will be indexed from 0 to N-1. The standard idiomatic for loop is then like this:
for ( int i = 0; i < N; ++i )
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
An array of size N will be indexed from 0 to N-1. The standard idiomatic for loop is then like this:
for ( int i = 0; i < N; ++i )
>It works fine as for(i=1;i<=n;i++) .
Yes it does. But then again, so does this:
Most programmers prefer to use the idiomatic approach because it's easier to use, easier to get used to, and common enough that you don't have to get used to something else everytime you read a different person's program.
Yes it does. But then again, so does this:
C Syntax (Toggle Plain Text)
i = 9; loopie: // Do stuff if ( --i > 9 - n ) goto loopie;
New members chased away this month: 3
•
•
•
•
Originally Posted by djextazy
It works fine as for(i=1;i<=n;i++) . Trust me. :lol:

C Syntax (Toggle Plain Text)
#include <stdio.h> #define N 10 int main() { int i, array[N] = {1,2,3,4,5,6,7,8,9,10}; for ( i = 1; i <= N; ++i ) { printf("array[%d] = %d\n", i, array[i]); } return 0; }
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Array of names (C)
- Storing names in an array. (C)
- Array Names (JavaScript / DHTML / AJAX)
Other Threads in the C Forum
- Previous Thread: Loop Issues
- Next Thread: Structural Equivalence Algorithm Question
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks bash binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h






