Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: implicit declaration of function 'system'

Tags:

c

I am getting an error in my compiler:

Warning: implicit declaration of function 'system'

I added:

system("cls");

To be able to clear the screen, and now I get the error. I am using this code to test:

#include <stdio.h>

int nothing; //random name

int main()
{
printf("this is a msg");
scanf("%d",&nothing);
system("cls");
printf("hello");
getchar();

return 0;
}

This is just a test code, so it's very sloppy. I am new to coding so any help would be appreciated.

like image 327
Noodle Avatar asked Nov 22 '25 09:11

Noodle


1 Answers

For C++: #include <cstdlib>, for C: #include <stdlib.h>.

Or, you can do as follows:

#ifdef __cplusplus__
  #include <cstdlib>
#else
  #include <stdlib.h>
#endif

if (system("CLS")) system("clear");

You can also see a full article w.r.t Clear the screen.

like image 162
duong_dajgja Avatar answered Nov 24 '25 01:11

duong_dajgja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!