Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to covert files to standard user input?

Instead of using files as input streams how can a user be made to input a string and then the string to be read character by character to check for prefix or postfix quotes?
how to convert in the follwing code, so that no files are used but standard input is used which is typed by the user and then character by character checks are out to find any quotes within the input?

#include
#include
#include
#include
char* point[100];

char* dumpstring(void)
{
static int disp=-1;
disp++;
return point[disp];
}

char* getstring(void)
{
static int count=1;
static int num=0;
fstream fin;
fin.open("TEXT.IN",ios::in);
char c[2];
for(int i=0;i<count;i++)
{
readagain: fin.read(c,1);
if(c[0]!='"') goto readagain;
else if(c[0]=='') return NULL;
}
long curpos=fin.tellg();
c[0]='';
for(i=0;c[0]!='"';i++) fin.read(c,1);
c[0]='';
char *str;
str=new char[i+1];
fin.seekg(curpos,ios::beg);
for(i=0;c[0]!='"';i++)
{
fin.read(c,1);
str[i]=c[0];
}
str[i-1]='';
count+=2;
for(i=0;point[i]!=NULL;i++)
{
if(strcmp(point[i],str)==0)
{
char* ret=point[i];
delete[] str;
fin.close();
return ret;
}
}
point[num]=str;
fin.close();
num++;
return str;
}

void main()
{
clrscr();
for(int i=0;i<100;i++) point[i]=NULL;
char* op;
int* opad;
cout<<"The Strings Encountered :
";
for(i=0;i<4;i++)
{
op=getstring();
cout<<i+1<<". ";
puts(op);
gotoxy(50,i+2);
opad=(int *)(op);
cout<<"stored at address : "<<opad<<"
";
}
cout<<"
The Strings Stored :
";
for(i=0;i<4;i++)
{
op=dumpstring();
if(op!=NULL)
{
cout<<i+1<<". ";
puts(op);
}
}
for(i=0;point[i]!=NULL;i++)
{
delete[] point[i];
}
getch();
}

Sign In or Register to comment.