Bug in a C code

Asked

Viewed 255 times

-1

I know, this code is very simple and this bit ugly tbm, I am beginner and I am trying to facilitate this function, someone can tell me what the mistake?

Screenshot of the bug:

inserir a descrição da imagem aqui

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
char tempo[5],a[25];
int op;

printf("EAE MEN\n\n1.Apagar o bixin\n2.Desligar e ligar dnv\n3.Tirar uma sonequinha\n");
scanf("%d",&op);

switch(op){
case 1:
a=="shutdown -s -t ";
printf("Desliga em qts segundos msm?\n");
scanf(" %s",tempo);
strcat(a,tempo);
break;
case 2:
a=="shutdown -r -t ";
printf("Reinicia em qts segundos msm?\n");
scanf(" %s",tempo);
strcat(a,tempo);
break;
case 3:
a=="shutdown -h -t ";
printf("Sonequinha em qts segundos msm?\n");
scanf(" %s",tempo);
strcat(a,tempo);
break;
default:
printf("Numero Invalido, bro, sabe ler n eh?\n");
return 0;
}
system(a);

return 0;
system("pause");
}
  • It would be nice [Dit] and put the code in the question. External references should only be used as a complement (and this is better for those who help you already see the whole problem in one place). Also, it is better to post the error as text, not as image.

  • 1

    Instead of error photos you can copy the error and paste it directly here, out that this is not a BUG but an error of your own, BUG would be if it was a failure in the C compiler you use, but the case ae is a mistake of yours. Read: Post code as image

1 answer

1


You are using the relational operator ==instead of the allocation operator =, in all declarations in which a, string, is left operator.

A string a is an array of type char. In C, you cannot make an assignment statement for this data type. You need to use the function strcpy(arrayDeDestino, arrayFonte).

  • I was wrong when sending the code, I was putting with = msm (as you can see in the error in cmd), I put == only to test msm knowing that I was wrong and sent the wrong one, and you can tell me what the msm error with a =

  • I edited the answer to get wider.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.