//i am writing a code that read from a file and store words in an character array but //in the wriiten by me,it is compiling but not extracting words in the array.
#include<iostream>
#include<fstream>
#include<string>
#include<string.h>
using namespace std;
int main()
{
ifstream fin;
char ch;
int j=0;
string line;
//reading from file.....
fin.open("rajkamal");//rajkamal is a valid file.
while(fin)
{
getline(fin,line);
}
cout<<"\n"<<line;
fin.close();
//putting data into an array from a string.
cout<<"\n"<<line;
char *a=&line[0];
cout<<endl;
cout<<a<<"******"<<endl;
cout<<a[0]<<a[1]<<a[2]<<a[3]<<endl;
int r=0,c1=0,i=0;
char word[10][10];
for(i=0;i<line.length();i++)
{
if(a[i]=' ')
{
word[r][c1++] = line[i];
}
else
{
word[r++][c1]=0;
c1=0;
}
}
word[r][c1]=0;
for(i=0;i<=r;i++)
{
cout<<word[i]<<"\n";
}
return 0;
}