Need Help with array...Please Advice 
Author Message
 Need Help with array...Please Advice

Let's say u have an array of char called
char arrayofchar[30]

how do u display the content of the array at the 20th location.
I have tried this but it doesn't work.
printf ("%s", arrayofchar[20]);



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice

Quote:
>Let's say u have an array of char called
>char arrayofchar[30]

>how do u display the content of the array at the 20th location.
>I have tried this but it doesn't work.
>printf ("%s", arrayofchar[20]);

You are telling printf() that you want to display a null-terminated
character string, when you really want to display a single character.

You should use "%c"

Also, the _first_ position is "arrayofchar[0]", the twentieth is
"arrayofchar[19]".

--
regards,

nick



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice

Quote:

> Let's say u have an array of char called
> char arrayofchar[30]

> how do u display the content of the array at the 20th location.
> I have tried this but it doesn't work.
> printf ("%s", arrayofchar[20]);

The element at the 20th location is a character not a string so
you need "%c" as your conversion format.

If you don't think of a 0th element the the 20th element is at
index 19 rather than 20.

The ouput will probably not actually appear until you send a '\n'
character.

I think you want:
  printf("%c\n",arrayofchar[19]);

Malcolm Kay



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice

Quote:

> Let's say u have an array of char called
> char arrayofchar[30]

> how do u display the content of the array at the 20th location.
> I have tried this but it doesn't work.
> printf ("%s", arrayofchar[20]);

printf("%c", arrayofchar[19]);        /* The 20th char */
printf("%s", arrayofchar+19); /* The string (if arrayofchar
                                   is 0-terminated) starting at the
                                   20th char */

--

What one knows is, in youth, of little moment; they know enough who
know how to learn. - Henry Adams

A thick skin is a gift from God. - Konrad Adenauer
__________________________________________________________
Fight spam now!
Get your free anti-spam service: http://www.brightmail.com



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice
aHmING a crit dans le message ...

Quote:
>Let's say u have an array of char called
>char arrayofchar[30]

>how do u display the content of the array at the 20th location.
>I have tried this but it doesn't work.
>printf ("%s", arrayofchar[20]);

Sure. You have an array of char, so an element is a char. The correct
formatter (?) for printf() is "%c".

printf ("%c\n", arrayofchar[20]);

and don't forget to include <stdio.h>

--
-hs- "Stove"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"Really?  When run on my machine, a printed copy of the C FAQ leaps
from the monitor and whacks me over the head.." -- Chris Mears CLC



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice

Quote:
>>how do u display the content of the array at the 20th location.
>printf ("%c\n", arrayofchar[20]);

and of course, the 20th location is at index 19.

printf ("%c\n", arrayofchar[19]);

--
-hs- "Stove"
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"Really?  When run on my machine, a printed copy of the C FAQ leaps
from the monitor and whacks me over the head.." -- Chris Mears CLC



Thu, 03 Oct 2002 03:00:00 GMT  
 Need Help with array...Please Advice
Thanks guys!!!


Quote:
> Let's say u have an array of char called
> char arrayofchar[30]

> how do u display the content of the array at the 20th location.
> I have tried this but it doesn't work.
> printf ("%s", arrayofchar[20]);



Fri, 04 Oct 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

2. Advice Please Really Need Help! :)

3. need help with arrays please

4. Help Please-need algorithm for getting 9 point average in 2d array

5. I need your advice. PLEASE

6. Need some advice on VC6 vs BCB5 please

7. Advice needed on sorting BIG arrays

8. help: Guru needed please please please

9. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

10. please help / advice

11. Help/advice please...

12. CreateFile and DeviceIOControl ... Help/Advice Please

 

 
Powered by phpBB® Forum Software