Reputation: 811
I wrote this C program for Win32/c compiler but while i'm trying run this using gcc in Linux machine or codepad.org it shows 'conio.h: No such file or directory compilation terminated' What are modification to be done to execute this program without including any other new includes like curses.h
#include<stdio.h>
#include<conio.h>
void main()
{
int i=0,j=0,k=0,n,u=0;
char s[100],c2,c[10];
char c1[3]={'a','b','c'};
clrscr();
printf("no of test cases:");
scanf("%d",&n);
for(u=0;u<n;u++)
{
printf("Enter the string:");
scanf("%s",s);
i=0;
while(s[i]!='\0')
{
if(s[i+1]=='\0')
break;
if(s[i]!=s[i+1])
{
for(j=0;j<3;j++)
{
if((s[i]!=c1[j])&&(s[i+1]!=c1[j]))
{
c2=c1[j];
}
}
s[i]=c2;
for(k=i+1;k<100;k++)
{
s[k]=s[k+1];
}
i=0;
}
else
i++;
}
c[u]=strlen(s);
}
for(u=0;u<n;u++)
printf("%d\n",c[u]);
getch();
}
Upvotes: 2
Views: 1495
Reputation: 1501
I did not look at your code to see if it needs the three functions. But this is the simplist way to get them. There is normaly a better way than using getch(). clrscr() is also no fun when you clear my screen !
#include<stdio.h>
#include <stdlib.h> // system
#include <string.h> // strlen
#include <termios.h> // getch
#include <unistd.h> // getch
void clrscr()
{
// Works on systems that have clear installed in PATH
// I don't like people clearing my screen though
system("clear");
}
int getch( )
{
struct termios oldt, newt;
int ch;
tcgetattr( STDIN_FILENO, &oldt );
newt = oldt;
newt.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newt );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
return ch;
}
Upvotes: 0
Reputation: 224972
It looks like the only functions you're using from conio.h
are clrscr()
and getch()
. Just take those out and you should be fine - they don't appear to affect the operation of the program. They're being used here more like workarounds for windows terminal behaviour.
A couple of notes:
main()
should return int
.strlen()
is defined in string.h
- you'll probably want to include that.Upvotes: 3
Reputation: 6791
Reviewing your question I can see that for clrscr() and getch() you are using conio.h But this header is not available in gcc. So for clrscr use
system("clear");
and as you have mentioned for getch() use the curses library
Cheers !!
Upvotes: 2