Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print out a slash (/ or \) in C?

Tags:

c

printf

I know this is a very silly and simple question but I've been trying to print out an image of a robot that should output this:

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

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

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

but an error showed, so I remembered that you need to double slash so:

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

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

like image 207
George Cavalevu Avatar asked Apr 22 '15 11:04

George Cavalevu


1 Answers

You don't need to escape forward slash.

This works for me:

#include <stdio.h>

int main()
{
  printf("| /\\  /\\ |");
  printf("| \\/  \\/ |");
  return 0;
}
like image 185
Benjy Kessler Avatar answered Oct 10 '22 10:10

Benjy Kessler