how to print upto a specified value in a charecter array in c??
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?
for(i=0;array[i]!='character';i++); character here could be any of the alphabets
can't put the ; before the print command.
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]);
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; }
#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; }
Join our real-time social learning platform and learn together with your friends!