-3

I am continuously getting that warning. I am sharing my code , please see and tell where is pointer.

#include<stdio.h>

int main() {
  int ageofUser, age;
  char damru[100], professionUser[20], name[20];

  printf("Hello I am Damroo , your personal chatbot.\n But I can answer limited questions because I am in developing phase.\n so lets chat.\n So , What is your name ?\n");
  scanf("%s", &damru);

  printf("Ohkay, what is your age ?");
  scanf("%d", &ageofUser);

  printf("Ohkay , Mr. %d , What do you work ?", &ageofUser);
  scanf("%s", &professionUser);

  printf("Why don't you talk bidirectionally ?");
  if (scanf("%s", &name) == "What is your name ?");
  printf("I am damroo.");

  if (scanf("%d", &age) == "what is your age ?");
  printf("I was born on 17/02/2021");

  return 0;
}

I just want to know where is pointer. I can't find any.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Get_ Maths
  • 103
  • 4
  • Here you are trying to use a pointer `printf("Ohkay , Mr. %d , What do you work ?", &ageofUser);` instead of an integer, remove the `&`. – Cyclonecode Feb 17 '21 at 08:38
  • Also your usage of `scanf` is wrong. Read the documentation of `scanf` and fin out what the return value is. But anyway youf `if` have no effect here, because of the `;` at the end of the lines starting with `if` – Jabberwocky Feb 17 '21 at 08:39
  • Also, scanf returns the actual number of red elements. Comparing it to a string literal is never going to work: you may actually want to compare "age" char array with "What is your age ?", for example ,instead of the actual return value of scanf. – Nastor Feb 17 '21 at 08:40
  • 1
    Your compiler should tell you where the error is. Then you can identify the involved operands. For example, `"what is your age ?"` is used as a pointer) – Gerhardh Feb 17 '21 at 08:40
  • 1
    Detail: So if your user's age is 21, you address him as _"Mr. 21"_? – Jabberwocky Feb 17 '21 at 08:43
  • Like others said in the comments, you are also using `scanf()` the wrong way. – Cyclonecode Feb 17 '21 at 08:44
  • 1
    The root of the problem here is: you can't do programming by taking a chance at the syntax or by trial & error. You must actually understand what every single line you type does and how C actually works. Otherwise you will keep getting very strange errors and bugs that you have no idea where they are coming from. – Lundin Feb 17 '21 at 08:47
  • Read about `strcmp`, `strncmp`, `strcasecmp` and similar. – i486 Feb 17 '21 at 08:53

1 Answers1

1

The documentation of scanf(3) says

RETURN VALUE

On success, these functions return the number of input items successfully matched and assigned; this can be fewer than provided for, or even zero, in the event of an early matching failure.

Thus, you cannot compare scanf() with a string. You need to use strcmp():

char *str = "hello";
char *str_comp = "ello";

if (strcmp(str, str_comp) == 0) {
    // both are equal
} else {
    // otherwise, not
}

Note that you can compare a string constant directly.

For scanning the character arrays, don't introduce an ampersand sign in scanf():

scanf("%s", professionUser); // removed &

Similarly, you never need to put an ampersand in printf(). To code defensively, always check the return values of scanf(), fgets(), etc.

Rohan Bari
  • 7,482
  • 3
  • 14
  • 34