i not able to rectify the error..........

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
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>

struct tm
{
char day[3],month[3],year[5];
char hrs[3],min[3],sec[3];
int d,m,y,H,M,S;
char time[21];
//function for breaking time
void brk();
//function for checking correct time format

int check1();
int check2();
//function for converting strings to int
void convert();
}t1,t2;

void tm::convert()
{
d=atoi(day);
m=atoi(month);
y=atoi(year);
H=atoi(hrs);
M=atoi(min);
S=atoi(sec);
}



int tm::check2()
{
int u=0;
if(m>12||m==0||d>31||d==0||M>=60||S>=60||H>=24)
{u++;
return u;
}
if(m==2||m==4||m==6||m==9||m==11)
  {
   if(d>30)
    {
    u++;
    return u;
    }
  }

return u;
}

int tm::check1()
{
int i,u=0;
for(i=0;i<19;i++)
 {
 if((i==2||i==5||i==10||i==13||i==16)&&(time[i]!='-'))
   {
    u++;
    return u;
   }

 else if(!(isdigit(time[i])))
   {
   u++;
   return u;
   }
 }
 return u;
}


void tm::brk()
{
int i,j;

for(i=0,j=0;i<20;i++,j++)
{
 if(i==2||i==5||i==10||i==13||i==16)
   j=0;

 else if(i<2)
    day[j]=time[i];

 else if(i<5)
    month[j]=time[i];

 else if(i<10)
    year[j]=time[i];

 else if(i<13)
    hrs[j]=time[i];

 else if(i<16)
    min[j]=time[i];

 else if(i<19)
    sec[j]=time[i];

}
}

main()
{
clrscr();
int a=0,b=0;
A:
cout<<"\nenter time in format dd-mm-yyyy-HH-MM-SS only\n";
cout<< "\nenter time 1 :\n";
cin.getline(t1.time,20);
a=t1.check1();
if(a)
 {
 cout<<"\ninvalid format pls try again\n";
 cout<<"\npress ESC to exit or any other key to continue\n";
 if(getch()==27)
 exit(0);
 goto A;
 }

t1.brk();
t1.convert();
b=t1.check2();
if(b)
 {
 cout<<"\ncheck values max time can be 31-12-9999-23-59-59\n";
 cout<<"\npress ESC to exit or any other key to continue\n";
 if(getch()==27)
 exit(0);

 goto A;
 }

cout<<"\ntime input success, input time is : ";
puts(t1.time);

getch();
return 0;
}
What is the error?

In fact, wait. Stop. Go and read this first, and then come back.
http://www.cplusplus.com/forum/articles/1295/

Do you know that what you're using is a kind of hideous mutant version of C++ that any compiler from the last 15 years will refuse to compile?
Last edited on
the functions check1 and check2 are not working in desired way.
wht i want to do is input time in format dd-mm-yyyy-HH-MM-SS in a string time[].
then i want to check the whether the time entered by the user is in correct format and is within the limits by using functions check1 and check2 ,
but it seems there is problem with function brk which breaks the data of time string into different strings as those strings for eg . day, year etc doesn't display any data when i print them on screen.
i am using turbo c++ v3.0 shouldn't i use it.
if not so which compiler should i use?
Code::Blocks would be my recommendation, some people prefer Visual Studio but I try to stay clear of microsoft as much as possible.

other possibilities are text editors like notepad++, but then you would have to compile it yourself, an IDE like Code::Blocks is a lot friendlier.

turbo c++ is scary old, don't use it.
Last edited on
Everything that uses .h is ANCIENT! Toatly deprecated! And, BTW, turbo C++ 3.0 is 21 year old! The NEWEST version, 4.5, is 6 years old! I recommend Orwell Dev-C++.
should i download code::blocks with mingw or without it?
with, sorry I forgot to mention that, but you need it or you'll get a few problems.
that's okay.
bt can u help me rectifying the problem i mentioned.
Topic archived. No new replies allowed.