0

What is the meaning of cls: command not found error

void display(char name[][31], int 
q1[],int q2[], int q3[]){
int i;
float ave;

system("cls");

printf("    Name    Quiz 1   Quiz 2   
Quiz 3    Average     Remarks\n");

for (i=0;i<MAX;i++){

    ave = avg(q1[i],q2[i],q3[i]);

    printf("%d.)%s   \t%d \t%d \t%d 
    \t%6.2f\t\t",i+1,name[i],q1[i],q2[i],q3[i],ave);

        if (ave>=75.0)
            printf("Passed. \n");
        else
            printf("Failed. \n");
 }
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
xtie83
  • 1
  • 1
  • It means the `cls` command you are trying to execute could not be found. – Scott Hunter Oct 20 '22 at 12:26
  • 1
    `cls` is a DOS command (inherited in Windows for its DOS prompt/command line window environment) to clear the screen. Systems like Linux or macOS does not have this command. You should never use `system("cls")` (or the equally common `system("pause")`). – Some programmer dude Oct 20 '22 at 12:26
  • 1
    That you have `system("cls")` in your code without knowing what it does, indicates you have fallen into [the cargo cult programming trap](https://en.wikipedia.org/wiki/Cargo_cult_programming). This is a bad thing, and you need to learn how to get out of this trap. – Some programmer dude Oct 20 '22 at 12:27
  • 1
    @Someprogrammerdude: Are you certain the question in not what `system("cls")` does, but why there was an error in trying to do it? – Scott Hunter Oct 20 '22 at 12:29
  • In what environment are you running your code? Windows? – Gerhardh Oct 20 '22 at 12:32
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 20 '22 at 14:43
  • I am using codeblocks on mac os big sur. – xtie83 Oct 22 '22 at 06:42
  • It looks like the error is related to this syntax: scanf("%[^\n]s", name[i]); When I changed it to scanf("%s", name[i]); The output is fixed but will now allow input of two names with space. – xtie83 Oct 22 '22 at 06:46

1 Answers1

0

Summary

As per @Scott Hunter's and @Some programmer dude's comments to the question, this error indicates that some program tries to execute the command cls, but cannot find it. Most probably it is either dash, bash, sh, or other similar shell.

Details

Your code suggests that this error is a result of trying to call system("cls"). But, I wasn't able to get that same message executing this function. I was only able to find that executing it produces slightly different message: sh: 1: cls: not found. Try to execute the following code:

#include <stdio.h>

int main() {
  system("cls");
  return 0;
}

in either https://www.w3schools.com/c/tryc.php?filename=demo_compiler or https://ideone.com/ (in ideone you need to select the language "C").

On the other hand, I found that executing the command cls directly as a shell command (not within a C file) produces exactly the message you wrote: cls: command not found. Compare: https://ideone.com/XVQg4f

Either way, executing system("cls") shouldn't work on Linux nor macOS, as per @Some programmer dude's comment. It may work on Windows. If you want to clear the screen on Linux (I don't know about macOS), one way is to use the system("clear") call. It may not be the right way in your case, but certainly is of the simplest.

If you would like to know more about the system C function, I recommend reading man 3 system (available online for example here: https://man7.org/linux/man-pages/man3/system.3.html).

Related questions:

user20276305
  • 95
  • 1
  • 7