Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

how to print upto a specified value in a charecter array in c??

OpenStudy (anonymous):

as in how to print an array of characters until a given character? Do you know it's position in the array or are you essentially asking for a searching algorithm?

OpenStudy (anonymous):

for(i=0;array[i]!='character';i++); character here could be any of the alphabets

OpenStudy (anonymous):

can't put the ; before the print command.

OpenStudy (anonymous):

simple example for reading a character & printing those... char a[10]; for(i=0;i<10;i++) scanf("%c",a[i]); for(i=0;i<10;i++) printf("entered chars. are %c \n",a[i]);

OpenStudy (anonymous):

You would probably want to include string.h. My method: #include <stdio.h> #include <string.h> int main(int argc, char* argv[]){ const char *stopcondition = "put char to stop on here"; char *mystring = "Here's the char array to be searched."; char *c = mystring; while (*c){ if (strchr(stopcondition, *c)) printf("%c is in \"%s\"\n", *c, mystring); c++;} return 0; }

OpenStudy (anonymous):

#include<stdio.h> int main() { int i; char ch[5]; ch[0]='a'; ch[1]='v'; ch[2]='b'; ch[3]='n'; ch[4]='e'; int limit=sizeof(ch); //takes the size of array for(i=0;i<limit;i++) // loops upto the size of array and print its all element { printf("%c \n",ch[i]); } getch(); return 0; }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!