problem in cin
hello
i have a problem in cin characters
this is my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
typedef char dataline[81];
dataline line;
cout<<">";
cin>>input;
while(input!="XT")
{
if (input=="IN")
{
cin.getline(line,SIZE);
while(line[0]!='/'&&line[1]!='/'&&line[3]!='\0')
{
l1.insert(line);
cin.getline(line,SIZE);
}
}
else if(input=="LA")
l1.list();
else if(input=="DL")
l1.Delete();
else if(input=="MV")
{ cin>>movment;
l1.move(movment);
}
else if(input=="XT")
l1.EXIT();
else
cout<<"Error Command...!"<<endl;
cout<<">";
cin>>input;
}
/* my proplem here
cin.getline(line,SIZE);
while(line[0]!='/'&&line[1]!='/'&&line[3]!='\0')
{
l1.insert(line);
cin.getline(line,SIZE);
}
*/
|
when i trying to input lines
like :
IN
111 1111 1111 111
2222 2222 2222 222
//
should insert into the linked list these lines
111 1111 1111 111
2222 2222 2222 222
just
but it add the // as a line
how i can exclude two slashes??
any help ?
complete code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
//file LE.h
struct nodetype;
const int SIZE=81;
typedef char dataline[81];
typedef nodetype *nodeptr;
class LED
{
public:
LED();
~LED();
void insert(dataline lines);
void Delete();//delete currnt line
void move(int num);
int cnt();// To Find Number Of Nodes.
void list();
void EXIT();
private:
nodeptr head;
nodeptr current;
};
//file LE.cpp
#include"LE.h"
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
struct nodetype
{
char data[SIZE];
nodeptr link;
};
LED::LED()
{
head=NULL;
current=NULL;
}
LED::~LED()
{
nodeptr delptr;
while(head!=NULL)
{
delptr=head;
head=head->link;
delete delptr;
}
}
void LED::insert(dataline lines)
{
nodeptr newptr=new nodetype;
newptr->link=NULL;
for(int i=0;i<SIZE;i++)
newptr->data[i]=lines[i];
if(current != NULL)
{
nodeptr ptr=head;
while(ptr->link!=current)
ptr=ptr->link;
newptr->link=ptr->link;
ptr->link=newptr;
}
else if(head==NULL)
{
head=newptr;
}
else
{
nodeptr cur = head;
while( cur->link )
cur= cur->link;
cur->link=newptr;
}
}
void LED::list()
{
nodeptr put=current;
if(current==NULL)
cout<<"<<END>>\n";
else{
while(put!=NULL)
{
cout<<put->data<<endl;
put=put->link;
}
}
}
int LED::cnt()
{
nodeptr temp=head;
int c=0;
if(head==NULL)
return 0;
else
c++;
while(temp->link!=NULL)
{
c++;
temp=temp->link;
}
return c;
}
void LED::move(int num)
{ nodeptr ptrMove;
//current=NULL;
ptrMove=head;
int mMove;
int funX;
if(num<0)
{
funX=cnt()+num+1;//just for minus
mMove=abs(num);//for minus
if(mMove>cnt())
{
current=head;
cout<<current->data<<endl;
}
else if(mMove<=cnt())
{
for(int i=1;i<funX;i++)
{
ptrMove=ptrMove->link;
}
current=ptrMove;
cout<<current->data<<endl;
}
}
else if(num>cnt())
{
current=NULL;
cout<<"<<END>> "<<endl;
}
else
{
if (current==NULL)
cout<<"<<END>>"<<endl;
else
{
current=current->link;
cout<<current->data<<endl;
}
}
}
void LED::EXIT()
{
exit(1);
}
void LED::Delete()
{
nodeptr Delt;
if(current==head)
{
head=head->link;
}
Delt=current;
current=current->link;
delete Delt;
}
//client file
#include<iostream>
#include<cstdlib>
#include<cstddef>
#include"LE.h"
#include<string>
#include<cmath>
using namespace std;
int main()
{
cout<<"###############################################################################\n";
cout<<"# Line Editor \n";
cout<<"# Please Use these commands (IN,DL,MV,LI,EX). \n";
cout<<"# command (IN) To Insert A New Line,should be followed by tow slashes (//). \n";
cout<<"# Command (LA) To list All Lines.\n";
cout<<"# Command (MV) Should Be Followed By Integer In The Same Line.\n";
cout<<"# Command (DL) To Delete The Current Line.\n";
cout<<"# Command (XT) To Terminate The Program.\n";
cout<<"###############################################################################\n";
LED l1;
int movment;
string input;
dataline line;
cout<<">";
cin>>input;
while(input!="XT")
{
if (input=="IN")
{
cin.getline(line,SIZE);
while(line[0]!='/'&&line[1]!='/'&&line[3]!='\0')
{
l1.insert(line);
cin.getline(line,SIZE);
}
}
else if(input=="LA")
l1.list();
else if(input=="DL")
l1.Delete();
else if(input=="MV")
{ cin>>movment;
l1.move(movment);
}
else if(input=="XT")
l1.EXIT();
else
cout<<"Error Command...!"<<endl;
cout<<">";
cin>>input;
}
cout<<l1.cnt()<<endl;
system("pause");
return 0;
}
|
Last edited on
????
pls help guys :)
Topic archived. No new replies allowed.