errors in general execution..

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
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{       char line[100], wd[30][30],ch[40];
      int l,i,j=0,w=0,k=0;
clrscr();
 printf("ENTER  A LINE \n");
 gets(line);
  l= strlen(line);
for(i=0;i<l;i++)
{
if(line[i] != ' ')
{	   wd[j][k]=line[i];
 k++;
}
else
{	   wd[j][k]='\0';
	   j++;
 k=0;
}
     }
printf("enter word to be checked\n");
   scanf("%s" ,ch);
  for (i=0;i<j;i++)
  {
printf("%s\n",wd[i]);
	if (strcmp(wd[i],ch)==0) w++;
 }
printf("The total number words %d\n",w);
  getch();
  return 0;
  }



It threw 2 errors..
1. clrscr() undeclared (first use this function)
2. (Each undeclared identifier is reported only once for each function it appears in.)

It worked in turbo c++..
In code blocks,it failed...
why????
please help me in correcting the code.......
clrscr is not part of the C++ standard. This means that the function is not guaranteed to come with your compiler (and indeed, you should assume it doesn't). Turbo C++ is a very old compiler that came with a lot of non-standard things (in fact, it's so old that back then there was no standard).

Now that you are using a more modern compiler (well, I assume you are - the Code::Blocks IDE usually comes with a pretty recent compiler) you will have to use standard C++.

If you insist on clearing the console, pick something out of this article:

http://www.cplusplus.com/articles/4z18T05o/

Also:

1
2
3
#include<stdio.h>
#include<string.h>
#include<conio.h> 


Please don't ever ever use any of these headers in C++ (or at least until you know what you're doing and have a really good reason to). The first one has been replaced with cstdio, the second one with cstring (and frankly, since this is C++, you shouldn't be using C-strings unless you have to, and you don't have to for this), and conio.h is horribly non-standard and this code will not work at all on many modern systems.

printf? No thank you. This is C++. Use #include <iostream> and cout.

gets? Similarly horribly and very dangerous. Use cin.

Whatever you're using to learn C++. please stop. Throw it away. Find something from the last decade.
Last edited on
tnks

how shall i correct it??
how shall i correct it??


Don't call clrscr.

If you insist on clearing the console, pick something out of this article:

http://www.cplusplus.com/articles/4z18T05o/
Last edited on
thanks a lot......cleared it
cout also needs the function declaration????
Last edited on
cout also needs the function declaration????


It needs the #include <iostream> ....

It needs the proper use of namespace std....
thanks...
use of namespace std....

could u please explain it....
where shall i
refer for this namespace std??
1
2
3
4
5
# include<iostream>
int main()
{cout<<"hello world...";
return 0;
}

1.cout' undeclared (first use this function)
2.(Each undeclared identifier is reported only once for each function it appears in.)
Last edited on
1
2
3
4
5
6
# include<iostream>
using namespace std;
int main()
{cout<<"hello world...";
return 0;
}
thanks..it worked
Topic archived. No new replies allowed.