nid help in...
char str[6]
input is hello...
so it will be like this
[h][e][l][l][o] ryt?
how can i print each element seperately?
print h...
then e. then l. then l. then o...
individually...
tnx....
nid help in...
char str[6]
input is hello...
so it will be like this
[h][e][l][l][o] ryt?
how can i print each element seperately?
print h...
then e. then l. then l. then o...
individually...
tnx....
Use a for loop:
Code:char string [20]; int i; scanf ("%s", string); for (i=0; i < strlen(string); i++) { printf ("%c", string [i]); }
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
Things to avoid:Without specifying the maximum size, this has the same problem as gets.Code:scanf ("%s", string);
Learn to avoid this construct lest some day you use this idiom with a very long string.Code:for (i=0; i < strlen(string); i++)
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
what is the function of strlen?!
and before using it do i need to do?
#include<string.h>????
Find the string length.Originally Posted by rothj0hn
[edit]strlen[/edit]The function returns the number of characters in the string s, not including its terminating null character.
You should try to discover your compiler's Help/man pages and/or find a decent online reference for standard functions (happy googling).
Last edited by Dave_Sinkula; 02-06-2006 at 10:44 AM.
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*