String Array

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2005
Posts: 26
Reputation: Dabdob is an unknown quantity at this point 
Solved Threads: 0
Dabdob Dabdob is offline Offline
Light Poster

String Array

 
0
  #1
Dec 18th, 2005
Hi guys…
I want to write small program in C printing three or more people in array..how? please write to me the syntax as I am very poor in C..

How to define the name? and accept the conformation from the user? Either by yes or no

The printing should be like
Your name is (first name in array)
Your name is (second name in array)

Do you need to use Loop?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 26
Reputation: Dabdob is an unknown quantity at this point 
Solved Threads: 0
Dabdob Dabdob is offline Offline
Light Poster

Re: String Array

 
0
  #2
Dec 18th, 2005
Helloooooooo
please i really need help
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: String Array

 
0
  #3
Dec 18th, 2005
first, you need to write main() function
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.  
  6. // put your code here
  7. }

next declare a character array that will hold the name that you input from the keyboard
  1. #include <stdio.h>
  2.  
  3. int main()
  4.  
  5. {
  6. char name[80]; // allow up to 79 characters plus null terminator
  7. // put your code here
  8. }

call printf() to display the prompt, and fgets() to get the input from the keyboard.
  1. print("... < text goes here > ... ");
  2. fgets(name,sizeof(name),stdin);
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 26
Reputation: Dabdob is an unknown quantity at this point 
Solved Threads: 0
Dabdob Dabdob is offline Offline
Light Poster

Re: String Array

 
0
  #4
Dec 19th, 2005
Hi Ancient,
Thanks for your help,
well, that slove first part of the probelm, i think i need to have a loop...

Assume, I have three elements in array – test[‘A’ , ‘B’ , ‘C’]

I want in the printf function to print this Question with each element

Are you Mr. A
Are you Mr, B
Are you Mr. C

Waiting your support
Thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,442
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1474
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: String Array

 
0
  #5
Dec 19th, 2005
why wait for anyone to tell you -- try it yourself and find out.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: String Array

 
0
  #6
Dec 19th, 2005
Originally Posted by Dabdob
I want in the printf function to print this Question with each element
Why use printf? Just use cout.
Also, why use a char array when the STL provides a string class?

If it's three or MORE people then use a vector since you don't know the exact size.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC