char[] gets split

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
#include <C:\tLib\tofiffeLib.h>
#include <string>
#define č char(159)
#define Č char(172)
#define š char(231)
#define Š char(230)
#define ž char(167)
#define Ž char(166)
int main()
{
	pChar str='\0';
	SetHandles();
	MenuDisable();
	ConsoleName("rot14 coder by tofiffe");
	ConsoleSize(40,10);
	LOOP
	{
		for(int i=0;i<10;i++)
		{
			CreateBGLine(toCOORD(0,i),40,grey);
		}
		TextColor(hred,grey);
		gotoxy(0,0);
		cout<<"Vpi"<<š<<"i besedilo:(vnesi exit za izhod)";
		gotoxy(0,1);
		char str[512]={'\0'};
		cin>>str;
		int x=0;
		for(x=0;x<512; x++)
		{
			if(str[x]=='\0')break;
			if((str[x]>=65&&str[x]<=77)||(str[x]>=97&&str[x]<=109))
			{
				str[x]+=13;
			}
			else if((str[x]>=78&&str[x]<=90||str[x]>=110&&str[x]<=122))
			{
				str[x]-=13;
			}
			else if(str[x]==' ')
			{
				x++;
			}
		}
		string s;
		s.append(str,x);
		gotoxy(0,3);
		cout<<s;
		ENTERWAIT
	}
return EXIT_SUCCES;
}


this is the code I used for a rot(14,13, forgot xD) coder, but when you type in more than 1 word it codes 1st word, loops, codes 2nd word and so on...what's wrong here?
Last edited on
Use the getline function to read the whole line.
thank you!
Topic archived. No new replies allowed.