How do I print a forward slash (/ or \) in C?

I know this is a very stupid and simple question, but I was trying to print an image of a robot that should output this:

+----------+
|          |
| /\    /\ |
| \/    \/ |
|          |
|  [-=-=-] |
+----------+

      

The part I'm stuck on is printing eyes. originally I coded:

printf("| /\  /\ |");
printf("| \/  \/ |");

      

but the error was shown, so I remembered that you need to do the double slash like so:

printf("| \/\\  \/\\ |");
printf("| \\\/  \\\/ |");

      

but an error indicating that the implicit printf function declaration is showing even after that ?! I don't understand the error. Can someone please explain how to fix this?

+3


source to share


2 answers


You don't need to hide the forward slash.

This works for me:



#include <stdio.h>

int main()
{
  printf("| /\\  /\\ |");
  printf("| \\/  \\/ |");
  return 0;
}

      

+6


source


You must use \ before the backslash. Its a separate character. Like this



printf("| /\\  /\\ |\n");   
printf("| \\/  \\/ |"); 

      

+1


source







All Articles