I was trying to make a shell interpreter similar to DOS in C language (for fun obviously)
And when i type clear, as shown in the code below it should make it so it clears the screen. But it doesn't.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
char command[128];
int loop = 0;
void main(){
clrscr();
printf("Starting shell\n");
clrscr();
while ( loop == 0){
printf("command:");
scanf("%s", &command);
if(command=='clear'){
printf("Clearing screen");
clrscr();
}
/** Other Code **/
if(command=='clear')
it's not valid string comparison. use strcmp to compare string in C
.
It should be
if (!strcmp(command, "clear"))
{
printf("Clearing screen");
clrscr();
}