splitting string in array

splitting string in array - cout<<"\nenter char...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Q : writ c++ function and main program to enter array of string thin split number ,small letters, capital and letters in 3 arrays? #include<stdio.h> #include<iostream.h> #define n 100 void check(char a[],int nu[],char ch[],char sm[]) { int asci,b=0,j=0,k=0,f=0,i=0; while(a[f]!=0){ asci=a[f]; //================ { nu[b]=asci-48; b++; } //================= { ch[j]=a[f];j++;} //======================== { sm[k]=a[f];k++; } //====================== f++; } i=0; for(i=0;i<b;i++) cout<<" "<<nu[i];
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
i=0; cout<<endl; for(i=0;i<k;i++) cout<<" "<<sm[i]; i=0; cout<<endl; for(i=0;i<j;i++) cout<<" "<<ch[i]; cout<<endl; } void main() { { int num[n],i=0; char cap[n],small[n],c[n];
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<<"\nenter char : = "; cin>>c; // While the string isn't at the end. .. { check(c,num,cap,small); } } } Second way ---------------#include<stdio.h> #include<iostream.h> #define n 20 int check(char ch) { if(ch>='0' && ch<='9') return 1; else if((ch>='a'&&ch<='z')||(ch>='A'&& ch<='Z')) return 2; else return 3; } void main() { int x,i=0,j=0,k=0; char c,a[n],b[n],d[n]; while(c !='$') { cin>>c; //c=getchar(); x=check(c); if(x==1){ a[i]=c;i++; } else if(x==2) {b[j]=c;j++;} else if(x==3) {d[k]=c; k++; } //cout<<" "<<x<<endl; } for(int f=0;f<i;f++) cout<<" "<<a[f]; cout<<endl; for( f=0;f<j;f++) cout<<" "<<b[f]; cout<<endl; for( f=0;f<k;f++) cout<<" "<<d[f]; }...
View Full Document

This note was uploaded on 10/16/2010 for the course ENG 2266e taught by Professor Aliraqi during the Spring '10 term at 4.1.

Page1 / 4

splitting string in array - cout<<"\nenter char...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online